Reputation: 45737
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!
Upvotes: 1
Views: 206
Reputation: 50976
$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
}
Upvotes: 3
Reputation: 20404
if (strpos($string, "/store/") !== false) {
// found
} else {
// not found
}
Upvotes: 2
Reputation: 22633
Seems like you're looking for the stristr() function.
$string = "blabla/store/home/blahblah";
if(stristr($string, "/store/")) { do_something(); }
Upvotes: 1
Reputation: 3442
Try using the strrpos function
e.g.
$pos = strrpos($yourstring, "b");
if ($pos === true) { // note: three equal signs
//string found...
}
Upvotes: 1