what is the syntax if the STRISTR() function in php?
stristr(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 STRISTR() 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 stristr("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 stristr("Hello world!",111);
?>
Example 3. In this example, we return the part of the string before the first occurrence of “world”.
<?php
echo stristr("Hello world!","WORLD",true);
?>