How to use php stristr function?
php The stristr function is used to search for the first occurrence of a string in another string. Its syntax is stristr(string,search,before_search). The parameter string is required and specifies the string to be searched; search is required and specifies The string to search for.
#php How to use stristr function?
Definition and Usage
stristr() function searches for the first occurrence of a string within another string.
Note: This function is binary safe.
Note: This function is not case sensitive. For case-sensitive searches, use the strstr() function.
Syntax
stristr(string,search,before_search)
Parameters
string Required. Specifies the string to be searched for.
search Required. Specifies the string to search for.
If the parameter is a number, search for characters matching the ASCII value corresponding to the number.
before_search Optional. The default value is a Boolean value of "false".
If set to "true", it will return the portion of the string before 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.
PHP version: 4
Change log:
In PHP 5.3, the before_search parameter is added.
In PHP 4.3, this function becomes binary safe.
Example 1
Search for a string with the ASCII value of "o" and return the remainder of the string:
<?php echo stristr("Hello world!",111); ?>
Output:
o world!
Example 2
Return the part of the string before the first occurrence of "world":
<?php echo stristr("Hello world!","WORLD",true); ?>
Output:
Hello
Example 3
Find the first occurrence of "world" in "Hello world!" and return the rest of the string:
<?php echo stristr("Hello world!","WORLD"); ?>
Output:
world!
The above is the detailed content of How to use php stristr function?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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









