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. 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.
<?php$haystack1 = "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");p rint (" POS1 = ($pos 1); Type is ". GetType ($pos 1). "\ n");p rint ("Pos2 = ($pos 2); Type is ". GetType ($pos 2). "\ n");p rint ("POS3 = ($pos 3); Type is ". GetType ($pos 3). "\ n");? >
Output Result:
POS1 = (13); Type is Integerpos2 = (0); Type is INTEGERPOS3 = (); Type is Boolean
POS3 returns a bool value, i.e. no substring found
Summary : The above is the entire content of this article, I hope to be able to help you learn.