The example in this article describes how PHP uses the strstr() function to obtain all characters after a specified string. Share it with everyone for your reference, the details are as follows:
PHP’s strstr() function can search for the first occurrence of a string in another string and return the remaining part of the string.
strstr() function is defined as follows:
strstr(string,search,before_search)
Parameter description:
string required. Specifies the string to be searched for.
search
Required. Specifies the string to be searched for.
If this parameter is a number, search for characters matching the ASCII value corresponding to this number.
before_search
Optional. The default value is a Boolean value of "false".
If set to "true", it will return the part of the string before the first occurrence of the search parameter.
The sample code is as follows:
<?php echo strstr("欢迎来到本站","脚本"); echo "<br/>"; echo strstr("Welcome To www.jb51.net","jb51"); echo "<br/>"; echo strstr("123456789","5"); ?>
The running result is as follows:
本站 jb51.net 56789
Added:
The third optional parameter of the strstr() function can only be used after PHP5.3 version, such as:
echo strstr("123456789","5",true); //输出:1234
For more information about PHP string operations, please see the special topic on this site: "Summary of PHP String Usage"
I hope this article will be helpful to everyone in PHP programming.
The above introduces how PHP uses the strstr function to obtain all characters after a specified string, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.