1

I have these two strings:

blablab/wp-forum.php?link

blablab/wp-forum.php

How can I check in PHP if the second one is contained in the first one or not?

I cannot find a working and easy way.

Thanks

3 Answers 3

2

Check out the docs for the function strstr
Or strpos
Or preg_match

1
  • strpos("blablab/wp-forum.php?link", "blablab/wp-forum.php")
    – Julien
    Commented Mar 5, 2012 at 22:45
1
$str = "blablab/wp-forum.php?link";
$find = "blablab/wp-forum.php";

$position = strpos($str, $find);

if($position !== FALSE)   // !== operator to check the type as well. As, strpos returns 0, if found in first position
{
   echo "String contains searched string";
}
0

You can use strpos to locate the first occurence of such a string

      <?php 
      $pos = strpos($largerString,$fimdMe);
      if($pos === false) {
        // string $findMe not found in $largerString
      }
     else {
      // found it 
    }
    ?>

Not the answer you're looking for? Browse other questions tagged or ask your own question.