1
2<?php
3$mystring = 'abc';
4$findme = 'a';
5$pos = strpos($mystring, $findme);
6
7// Note our use of ===. Simply == would not work as expected
8// because the position of 'a' was the 0th (first) character.
9if ($pos === false) {
10 echo "The string '$findme' was not found in the string '$mystring'";
11} else {
12 echo "The string '$findme' was found in the string '$mystring'";
13 echo " and exists at position $pos";
14}
15?>
16
17
1strrpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int or False return
2<?php
3$foo = "0123456789a123456789b123456789c";
4
5// Looking for '0' from the 0th byte (from the beginning)
6var_dump(strrpos($foo, '0', 0));
7
8// Looking for '0' from the 1st byte (after byte "0")
9var_dump(strrpos($foo, '0', 1));
10
11$str = 'This is Main String';
12
13if (strpos($str, 'This') !== false) {
14 echo 'true';
15}
16