strpos   PHP


Summary

Find the position of the first occurrence of a substring in a string


Requirements

None.


strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int

<?php
$str = 'abcd';

$pos_a = strpos($str, 'a');
$pos_e = strpos($str, 'e');

var_dump($pos_a);
var_dump($pos_e);

if($pos_e === false) {
    echo "the String 'e' was not found in the string '$str'";
} else {
    echo "the String 'e' exists at position $pos_e";
}

?>


Result

int(0) bool(false) the String 'e' was not found in the string 'abcd'

References


Tags

#string  #strpos 


[ Edit (Author only) ]