PHP Strpos () function
PHP String function
Definition and usage
The Strpos () function returns the position of the first occurrence of a string in another string.
If the string is not found, false is returned.
Grammar
Strpos (String,find,start)
Parameters |
Description |
String |
Necessary. Specifies the string to be searched. |
Find |
Necessary. Specifies the character to find. |
Start |
Optional. Specify where to start the search. |
Hints and Notes
Note: The function is case-sensitive. Use the Stripos () function if you want to search for case insensitive.
Example
<?php
strpos("Hello world!","wo")
;
?>
Output:
6
PHP Strripos () function
PHP String function
Definition and usage
The Strripos () function finds the position of the last occurrence of a string in another string.
If successful, returns the position, otherwise false.
Grammar
Strrpos (String,find,start)
Parameters |
Description |
String |
Necessary. Specifies the string to be searched. |
Find |
Necessary. Specifies the character to find. |
Start |
Optional. Specify where to start the search. |
Hints and Notes
Note: The function is not case sensitive. For case-sensitive lookups, use Strrpos ().
Example
<?php
strripos("Hello world!","WO")
;
?>
Output:
6
PHP similar to IndexOf method [go]