Home > Backend Development > PHP Tutorial > PHP uses strstr function to get all characters after a specified string

PHP uses strstr function to get all characters after a specified string

WBOY
Release: 2016-07-29 09:07:28
Original
2485 people have browsed it

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:

<&#63;php
 echo strstr("欢迎来到本站","脚本");
 echo "<br/>";
 echo strstr("Welcome To www.jb51.net","jb51");
 echo "<br/>";
 echo strstr("123456789","5");
?>

Copy after login

The running result is as follows:

本站
jb51.net
56789

Copy after login

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

Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template