This article mainly introduces php's method to find sub-strings in specified strings. it involves the strpos () function in php to find strings. it has some reference value, for more information about how to search for substrings in a specified string in php, see the following example. Share it with you for your reference. The specific analysis is as follows:
The strpos () function can be used to search for substrings in php. The strpos () function will try to find the position where the substring first appears in the source string. If yes, it returns a non-negative integer indicating the position where the substring appears. Otherwise, it returns a boolean value of false.
<? Php $ haystack1 = "courier"; $ haystack2 = "courier"; $ haystack3 = "center234953413434516504381640369488129fyi"; $ pos1 = strpos ($ haystack1, "w3mentor "); $ pos2 = strpos ($ haystack2, "w3mentor"); $ pos3 = strpos ($ haystack3, "w3mentor"); print ("pos1 = ($ pos1); type is ". gettype ($ pos1 ). "\ n"); print ("pos2 = ($ pos2); type is ". gettype ($ pos2 ). "\ N"); print ("pos3 = ($ pos3); type is". gettype ($ pos3). "\ n");?>
Output result:
Pos1 = (13); type is integerpos2 = (0); type is integerpos3 = (); type is boolean
Pos3 returns the bool value, that is, the substring is not found.
I hope this article will help you with php programming.