0

In SQL there is the LIKE parameter that you can put in to have a wild card for values such as: LIKE %value%. How would I be able to do that with, say, a PHP if statement?

$value = "value-";

$post = $_POST['retrievedVal'];

if($value.% == $post)
{
   echo "true";
}
Majo0od
  • 2,278
  • 10
  • 33
  • 58
  • 1
    This might help: http://stackoverflow.com/questions/2790899/php-how-to-check-if-a-string-starts-with-a-specified-string –  May 24 '13 at 14:36

1 Answers1

1

As far as I know there is none, but don't worry there is a way to achieve the same with strpos()

just use the following if statement:

if(false !== strpos($post, $value)){
    // you thing to do
}

beware strpos could return 0, so the explicit comparison is needed

Avisek Chakraborty
  • 8,229
  • 10
  • 48
  • 76
MKroeders
  • 7,562
  • 4
  • 24
  • 39