php string indexof code example
Example 1: strpos in php
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
Example 2: php indexof
strrpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int
Example 3: php indexof
strrpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int or False return
<?php
$foo = "0123456789a123456789b123456789c";
var_dump(strrpos($foo, '0', 0));
var_dump(strrpos($foo, '0', 1));
$str = 'This is Main String';
if (strpos($str, 'This') !== false) {
echo 'true';
}