我有这两个字符串:
blablab/wp-forum.php?link
blablab/wp-forum.php
如何在PHP中检查第二个是否包含在第一个 我找不到一种既有效又简单的方法。 感谢
查看函数strstr的文档
或strpos
或preg_match
$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";
}
您可以使用strpos
来定位此类字符串的第一个出现
<?php
$pos = strpos($largerString,$fimdMe);
if($pos === false) {
// string $findMe not found in $largerString
}
else {
// found it
}
?>