时间:2021-07-01 10:21:17 帮助过:5人阅读
php
$mystring = 'abc';
$findme= 'a';
$pos = strpos($mystring, $findme);
// Note our use of ===.Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'\";
} else {
echo \"The string '$findme' was found in the string '$mystring'\";
echo \" and exists at position $pos\";
}
// We can search for the character, ignoring anything before the offset
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
?>
php
$mystring = "Hello Chris\";
if (substr_count($mystring, \"Hello\") == 0)
echo \"no\";
// same as:
if (strpos($mystring, \"Hello\") === false)
echo \"no\";
?>
php
$val1=123;
$val2="123,456,789\";
if (strpos($val2, $val1)!==false) echo \"matched\";
else echo \"not matched\";
?>
结果为: not matched
php
$val1=(string)123;
$val2="123,456,789\";
if (strpos($val2, $val1)!==false) echo \"matched\";
else echo \"not matched\";
?>
结果为:not matched