How to use php strstr function

青灯夜游
Release: 2023-03-11 09:52:01
Original
2031 people have browsed it

In PHP, the strstr() function is used to determine whether a string exists in another string. The syntax format is "strstr(string,search,before_search)"; if so, return the string and the remaining part, otherwise returns FALSE.

How to use php strstr function

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

strstr() function is a built-in function in PHP . This function searches for the presence of a string in another string; it searches for the first occurrence of that string in another string and displays the latter part. This function is case-sensitive.

Syntax

strstr(string,search,before_search)
Copy after login
ParametersDescription
string Required. Specifies the string to be searched for.
searchRequired. Specifies the string to search for. If the argument is a number, searches for characters that match the ASCII value for that number.
before_search Optional. A Boolean value with a default value of "false". If set to "true", it will return the portion of the string preceding the first occurrence of the search parameter.

Return value: Returns the remaining part of the string (from the matching point). Returns FALSE if the searched string is not found.

Example 1: Determine whether "world" exists in "Hello world!"

<?php
echo strstr("Hello world!","world");
?>
Copy after login

Output:

world!
Copy after login

Example 2: Search a string by the ASCII value of "o" and return the remaining part of the string

<?php
echo strstr("Hello world!",111);
?>
Copy after login

Output:

o world!
Copy after login

Recommended learning:《 PHP video tutorial

The above is the detailed content of How to use php strstr function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!