PHP检查字符串中包含的子串
示例
<?php$subStr = "Mother";
$str = "How I Met Your Mother";
echo "String = $str";
echo "\nSubstring = $subStr";
if(strpos($str, $subStr) !== false){
echo "\n成功找到子字符串";
} else{
echo "\n找不到子字符串";
}
?>
输出结果
String = How I Met Your MotherSubstring = Mother
成功找到子字符串
示例
现在让我们来看另一个示例-
<?php$subStr = "Ocean";
$str = "In the Heart of Sea";
echo "String = $str";
echo "\nSubstring = $subStr";
if(strpos($str, $subStr) !== false){
echo "\n成功找到子字符串";
} else{
echo "\n找不到子字符串";
}
?>
输出结果
String = In the Heart of SeaSubstring = Ocean
找不到子字符串
以上是 PHP检查字符串中包含的子串 的全部内容, 来源链接: utcz.com/z/350378.html