PHP strstr Function



PHP Tutorial > String Functions > strstr Function

The strstr function in PHP is used to return all characters of a string after the first match. The syntax of the strstr function is:

strstr ('string', 'match_pattern', [before_indicator])

If the optional before_indicator parameter is set to TRUE, the strstr function returns all characters of a string before the first match. before_indicator is introduced in PHP 5.3.0.

Let's take a look at the examples below:

Example 1

print strstr ('PHP strstr function','str');

Result:

strstr function

Example 2

print strstr('PHP strstr function','str', TRUE);

Result:

PHP

Next: PHP substr Function



Copyright © 2023   1keydata.com  All Rights Reserved.  Privacy Policy   About   Contact