Php strpos
From w3cyberlearnings
Contents |
PHP function strpos
This function finds the first occurence of a string within another string.
Syntax strpos
- string: string input.
- find: string to find.
- startpos: specifies where the search to begin.
strpos(string, find, startpos);
Return
Return the first position of the string.
Example 1
<?php echo strpos('Great work!',"t"); ?>
Output
4
Example 2
<?php $arr = array('Great', 'Excellent', 'Lovely', 'Healthy'); for ($i = 0; $i < count($arr); $i++) { echo 'e is located at position ' . strpos($arr[$i], 'e') . ' in ' . $arr[$i] . '<br/>'; } ?>
Output
e is located at position 2 in Great e is located at position 3 in Excellent e is located at position 3 in Lovely e is located at position 1 in Healthy