How to use php strstr function
Jul 06, 2021 pm 05:41 PMIn 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.
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)
Parameters | Description |
---|---|
string | Required. Specifies the string to be searched for. |
search | Required. 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"); ?>
Output:
world!
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); ?>
Output:
o world!
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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
