Home >Backend Development >PHP Tutorial >Find characters in php string_PHP tutorial
What this article is going to talk about is using the strstr and strpos functions to query whether there is the character content we want in the specified string. You can refer to it if you need it.
The strstr() function is used to obtain the substring from the first occurrence of a specified string in another string to the end of the latter. If the execution is successful, it returns the remaining string (matching characters exist); If no matching character is found, false is returned.
Syntax:
string strstr(string haystack,string needle)
Parameter haystack: necessary parameter, specify which string to search from.
Parameter needle: necessary parameter, specifying the search object. If the argument is a numeric value, then a search is performed for characters that match the ASCII value of the numeric value.
Example:
The code is as follows
|
Copy code
|
||||
echo strstr("Tomorrow's Programming Dictionary","Editor"); //Output the query string
echo “ ”; //Execute carriage return echo strstr("www.111c.net","111"); //Output the query string (value from the first m) echo “”; //Execute carriage return
echo strstr(“0431-84972266″,”8″); //Output the query string
|
find required. Specifies the characters to search for.