Php implements the method of searching for substrings in a specified string. Php: how to find a substring in a specified string this article mainly introduces the php method to find a substring in a specified string, involving strpos () in php () function search string technology php implements the method of searching for substrings in a specified string
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, see
This example describes how to find a substring in a specified string in php. 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.
?
1 2 3 4 5 6 7 8 9 10 11 |
$ Haystack1 = "2349534134345w3mentor16504381640415488129 "; $ Haystack2 = "w3mentor234953413434516504381640410488129 "; $ Haystack3 = "center234953413434516504381640109488129fyi "; $ 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:
?
1 2 3 |
Pos1 = (13); type is integer Pos2 = (0); type is integer Pos3 = (); 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.
This article describes how to use php to find sub-strings in specified strings. it involves the strpos () function in php to find strings...