PHP Tutorial - PHP strripos() Function






Definition

The strripos() function finds the position of the last occurrence of a string inside another string. The strripos() function is case-insensitive.

Syntax

PHP strripos() Function has the following syntax.

strripos(string,find,start)

Parameter

ParameterIs RequiredDescription
stringRequired.String to search
findRequired.String to find
startOptional.Where to begin the search




Return

PHP strripos() Function returns the position of the last occurrence of a string inside another string, or FALSE if the string is not found.

String positions start at 0, and not 1.

  • stripos() - Finds the position of the first occurrence of a string inside another string (case-insensitive)
  • strpos() - Finds the position of the first occurrence of a string inside another string (case-sensitive)
  • strrpos() - Finds the position of the last occurrence of a string inside another string (case-sensitive)




Example

Find the position of the last occurrence of "php" inside the string:


<?php
echo strripos("php from java2s.com","PHP");
?>

The code above generates the following result.