Easy Tutorial
❮ Func Xml Parse Func Curl_Multi_Close ❯

PHP strstr() Function

PHP String Reference Manual

Example

Check if "world" exists in "Hello world!" and if so, return the string and the remaining part:

<?php
echo strstr("Hello world!", "world");  // Outputs world!
?>

Definition and Usage

The strstr() function searches for a string within another string. If found, it returns the string and the remaining part; otherwise, it returns FALSE.

Note: This function is binary-safe.

Note: This function is case-sensitive. For case-insensitive search, use the stristr() function.


Syntax

Parameter Description
string Required. Specifies the string to be searched.
search Required. Specifies the string to search for. If this parameter is a number, it searches for the character matching the ASCII value of the number.
before_search Optional. A boolean value with a default of "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter.

Technical Details

Return Value: Returns the remaining part of the string (from the match point). If the search string is not found, it returns FALSE.
PHP Version: 4+
--- ---
Changelog: The before_search parameter was added in PHP 5.3.
--- ---

More Examples

Example 1

Search for the string using the ASCII value of "o" and return the remaining part of the string:

Example 2

Return the part of the string before the first occurrence of "world":


PHP String Reference Manual

❮ Func Xml Parse Func Curl_Multi_Close ❯