如何在PHP中检查字符串是否包含特定内容?
我需要一个php函数,它将以这种方式工作如何在PHP中检查字符串是否包含特定内容?,php,string,Php,String,我需要一个php函数,它将以这种方式工作 $string = "blabla/store/home/blahblah"; If in $string you find /store/ then do this, else do that. 我怎么做 谢谢 你要找的你要找的 或 或 尝试使用strrpos函数 e、 g 尝试使用strrpos函数 e、 g 看起来你在找函数 $string = "blabla/store/home/blahblah"; if(stristr($string,
$string = "blabla/store/home/blahblah";
If in $string you find /store/ then do this, else do that.
我怎么做
谢谢 你要找的你要找的
或
或
尝试使用strrpos函数 e、 g
尝试使用strrpos函数 e、 g
看起来你在找函数
$string = "blabla/store/home/blahblah";
if(stristr($string, "/store/")) { do_something(); }
看起来你在找函数
$string = "blabla/store/home/blahblah";
if(stristr($string, "/store/")) { do_something(); }
文档不鼓励这样做。首选strpos:如果只想检查一个字符串是否包含在另一个字符串中,请不要使用preg_match。使用strpos或strstr,因为它们会更快。在这个特定的示例中,使用strpos更好,因为它完成了相同的任务,并且比正则表达式更快。strpos可以返回0,这意味着我在一开始就找到了它,但是0是错误的,您的if语句将导致错误的结果。+1给出了很好的示例,但正如:如果只想检查一个字符串是否包含在另一个字符串中,请不要使用preg_match。请改用STRPO或strstr,因为它们会更快。文档不鼓励这样做。首选strpos:如果只想检查一个字符串是否包含在另一个字符串中,请不要使用preg_match。使用strpos或strstr,因为它们会更快。在这个特定的示例中,使用strpos更好,因为它完成了相同的任务,并且比正则表达式更快。strpos可以返回0,这意味着我在一开始就找到了它,但是0是错误的,您的if语句将导致错误的结果。+1给出了很好的示例,但正如:如果只想检查一个字符串是否包含在另一个字符串中,请不要使用preg_match。请改用strpos或strstr,因为它们会更快。如果strpos$string,/store/!==false{do_something;}ifstrpos$string,/store/!==假{做点什么;}
$pos = strrpos($yourstring, "b");
if ($pos === true) { // note: three equal signs
//string found...
}
$string = "blabla/store/home/blahblah";
if(stristr($string, "/store/")) { do_something(); }
if (strpos($string, "/store/") !== false) {
// found
} else {
// not found
}