PHP implements a method to find substrings in a specified string
This article mainly introduces the PHP implementation of the specified string to find a substring of the method, involving PHP strpos () function to find the string of skills, with a certain reference value, the need for friends can refer to the following
The example in this article describes the way that PHP implements finding substrings in a specified string. Share to everyone for your reference. The specific analysis is as follows:
The Strpos () function can be used to find substrings in PHP. The Strpos () function will attempt to find the location where the substring first appears in the source string. If found, it returns a non-negative integer indicating where the substring appears. Otherwise it returns a Boolean value of false.
?
1 2 3 4 5 6 7 8 9 10 11 |
$haystack 1 = "2349534134345w3mentor16504381640386488129"; $haystack 2 = "w3mentor234953413434516504381640386488129"; $haystack 3 = "CENTER234953413434516504381640386488129FYI"; $pos 1 = strpos ($haystack 1, "W3mentor"); $pos 2 = Strpos ($haystack 2, "W3mentor"); $pos 3 = Strpos ($haystack 3, "W3mentor"); Print ("POS1 = ($pos 1); Type is ". GetType ($pos 1). "\ n"); Print ("Pos2 = ($pos 2); Type is ". GetType ($pos 2). "\ n"); Print ("POS3 = ($pos 3); Type is ". GetType ($pos 3). "\ n"); ?> |
Output Result:
?
1 2 3 |
POS1 = (13); Type is integer Pos2 = (0); Type is integer POS3 = (); Type is Boolean |
POS3 returns a bool value, i.e. no substring found
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/969354.html www.bkjia.com true http://www.bkjia.com/PHPjc/969354.html techarticle PHP implements a method to find substrings in a specified string this article mainly introduces the method of finding substrings in the specified string in PHP, involving the Strpos () function in PHP to find the string ...