Home > Backend Development > PHP Tutorial > When using strpos under expandenvironmentstrings php, you need to pay attention to the === operator

When using strpos under expandenvironmentstrings php, you need to pay attention to the === operator

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:43:13
Original
1789 people have browsed it

Copy code The code is as follows:


/*
Function to determine whether a string exists
*/
function strexists($haystack, $needle) {
return !(strpos($haystack , $needle) === FALSE);//Note here "==="
}
/*
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 The use of "==" 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
// When searching for characters, you can use the parameter offset to specify the offset
$newstring = 'abcdef abcdef';
$pos = strpos($newstring , 'a', 1); // $pos = 7, not 0
?>

The above introduces the === operator that needs to be paid attention to when using strpos under expandenvironmentstrings PHP, including the content of expandenvironmentstrings. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template