Home>

php's strstr () function searches for the first occurrence of a string in another string,And return the rest of the string.

The strstr () function is defined as follows:

strstr (string, search, before_search)

Parameter Description:

string is required. Specifies the string to be searched.

search

essential. Specifies the search string.

If this parameter is numeric,Search for characters that match the ascii value for this number.

before_search

Optional. The default value is a Boolean value of "false".

If set to "true", it returns the part of the string before the first occurrence of the search parameter.

The sample code is as follows:

<?php
 echo "<br />";
 echo "<br />";
 echo strstr ("123456789", "5");
?>

The results are as follows:

jb51.net
56789

supplement:

The third optional parameter to the strstr () function is only available after PHP 5.3.Such as:

echo strstr ("123456789", "5", true);
//Output:1234
php
  • Previous Example analysis of javascript motion framework usage (to achieve zoom-in and zoom-out effects)
  • Next PHP image cropping and cropping source code and usage method