If you only want to look, if a string appears in another string - even at position 0 - , you can also use substr_count():
<?php
$mystring = "Hello Chris";
if (substr_count($mystring, "Hello") == 0)
echo "no";
// same as:
if (strpos($mystring, "Hello") === false)
echo "no";
?>
本文介绍了一种使用PHP语言检查一个字符串是否包含另一个字符串的方法。通过使用substr_count()和strpos()函数,可以有效地判断一个字符串是否出现在另一个字符串中,即使出现在位置0也能正确处理。
3588

被折叠的 条评论
为什么被折叠?



