PHP判断字符串是否包含某个字符串,可以使用strpos函数。该函数返回字符串在另一个字符串中第一次出现的位置,如果没有找到该字符串,则返回false。
PHP判断字符串是否包含某个字符串,可以使用strpos函数。该函数返回字符串在另一个字符串中第一次出现的位置,如果没有找到该字符串,则返回false。
代码如下:
$string = "Hello World";
$findme = "World";
$pos = strpos($string, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$string'";
} else {
echo "The string '$findme' was found in the string '$string'";
echo " and exists at position $pos";
}
?>
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(74条)