Copy code The code is as follows:
/*
Function to determine whether a string exists
*/
function strexists($haystack, $needle) {
return !(strpos($haystack, $needle) === FALSE);//Note the "==="
}
/*
Test
*/
$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.
// Simple Using the "==" sign will not work, you need to use "===", because the first occurrence of a is 0
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
// You can use the offset parameter to specify the offset when searching for characters Amount
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
?>
http://www.bkjia.com/PHPjc/322253.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322253.htmlTechArticleCopy the code as follows: ?php /* Function to determine whether a string exists*/ function strexists($haystack, $needle) { return !(strpos($haystack, $needle) === FALSE);//Note here...