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

Sign up to request clarification or add additional context in comments.

1 Comment

strpos("blablab/wp-forum.php?link", "blablab/wp-forum.php")
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";
}

Comments

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 
    }
    ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.