Reputation: 45737
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
Upvotes: 1
Views: 195
Reputation: 8309
$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";
}
Upvotes: 1
Reputation: 2081
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
}
?>
Upvotes: 0
Reputation: 132018
Check out the docs for the function strstr
Or strpos
Or preg_match
Upvotes: 2