PHP strstr() ਫੰਕਸ਼ਨ
ਉਦਾਹਰਣ
Shanghai ਨੂੰ "I love Shanghai!" ਵਿੱਚ ਪਹਿਲੀ ਵਾਰ ਲੱਭੋ ਅਤੇ ਸਟ੍ਰਿੰਗ ਦਾ ਬਾਕੀ ਪਾਰਟ ਵਾਪਸ ਦੇਓ:
<?php echo strstr("I love Shanghai!","Shanghai"); ?>
Definition and Usage
The strstr() function searches for the first occurrence of a string within another string.
Note:This function is binary safe.
Note:This function is case-sensitive. To perform a case-insensitive search, use stristr() Function.
Syntax
strstr(string,search,before_search)
Parameter | Description |
---|---|
string | Required. Specifies the string to be searched in. |
search |
Required. Specifies the string to be searched. If this parameter is a number, it will search for the character corresponding to the ASCII value of this number. |
before_search |
Optional. Default value is "false" boolean value. If set to "true", it will return search The string part before the first occurrence of the parameter. |
Technical Details
Return Value: | Return the remaining part of the string (from the match point). If the search string is not found, return FALSE. |
PHP Version: | 4+ |
Update Log: | Added in PHP 5.3: before_search Parameters. |
More Examples
Example 1
Search for the string with the ASCII value of "o" and return the remaining part of the string:
<?php echo strstr("Hello world!",111); ?>
Example 2
Return the string part before the first occurrence of the search string:
<?php echo strstr("Hello world!","world",true); ?>