I need a function in php that will work in this way.
$string = "blabla/store/home/blahblah";
If in $string you find /store/ then do this, else do that.
How can I do it?
Thanks!
if(strpos($string, "/store/") !== false) { do_something(); }$string = "blabla/store/home/blahblah";
if (preg_match("|/store/|", $string)){
//do this
}
else{
//do that
}
or
$string = "blabla/store/home/blahblah";
if (false !== strpos($string, "/store")){
//do this
}
else{
//do that
}
strpos() is better because it accomplishes the same thing and is faster than a regex.strpos can return 0 meaning "I found it at the very beginning", but 0 is falsy and your if statement will lead to an incorrect result.Seems like you're looking for the stristr() function.
$string = "blabla/store/home/blahblah";
if(stristr($string, "/store/")) { do_something(); }