PHP strpos()


strpos() function compare two strings, return the first occurrence position of the 2nd string inside the 1st string. If the 1st string do not contain the 2nd string, return FALSE. The first character position is 0. strpos() is case sensitive.

<?PHP
	echo strpos("This is a PHP tutorial","PHP");  //10
	echo strpos("The best time is no time at that time","time");  //9
	if (strpos("The best time is no time at that time","PHP"))
	{
	   echo "contain PHP";
	}
	else echo "do not contain PHP";
	//do not contain PHP
	echo strpos("This is a PHP tutorial","This");  //0
?>

If specify a offset, then the first occurrence position of the 2nd string inside the 1st string after the offset will be return.
<?PHP
	echo strpos("The best time is no time at that time","time", 10);  //20
?>


Similar function strrpos() finds the last occurrence of a substring.