English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strstr() Function Usage and Example

    PHP String Character String Functions Manual

The strstr() function is used to return the string from the position of the first occurrence to the end of the string.

Syntax

strstr(string,search,before_search)

Definition and Usage

The strstr() function searches for the existence of a string in another string, if it exists, returns the string and the remaining part, otherwise returns FALSE.

Note:This function is binary safe.

Note:This function is case-sensitive. To perform a case-insensitive search, please use stristr() Function.

Return Value

It returns the remaining part of the string; if the string is not found, it returns false

Parameter

Serial NumberParameter and Description
1

string

The string to be searched for

2

search

The string to be searched

3

before_search

A boolean value with a default value of "false". If set to "true", it will return the part of the string before the first occurrence of the search parameter.

Online Example

Try the following example, searches for the string by the ASCII value of "o" and returns the remaining part of the string

<?php
   //Searches for the string by the ASCII value of "o" and returns the remaining part of the string:
      echo strstr("Hello world!",111);
   echo '<br>';
   //Returns the part of the string before the first occurrence of "world"
   echo strstr("Hello world!","world",true);
?>
Test and see‹/›
o world!
Hello

PHP String Character String Functions Manual