what is the syntax of the STRSTR() function in php?
strstr(string,search,before_search)
Parameter | Description |
---|---|
string | Required. Specifies the string to search |
search | Required. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number |
before_search | Optional. A boolean value whose default is “false”. If set to “true”, it returns the part of the string before the first occurrence of the search parameter. |
examples of the STRSTR() function
Example 1. In this example, we find the first occurrence of “world” inside “Hello world!” and return the rest of the string.
<?php
echo strstr("Hello world!","world");
?>
Example 2. In this example, we search a string for the ASCII value of “o” and return the rest of the string:
<?php
echo strstr("Hello world!",111);
?>
Example 3. In this example, we return the part of the string before the first occurence of “world”.
<?php
echo strstr("Hello world!","world",true);
?>