PHP strripos() Function
Topic: PHP String ReferencePrev|Next
Description
The strripos()
function finds the position of the last occurrence of a string inside another string.
This function is case-insensitive. For case-sensitive searches, use the strrpos()
function.
The following table summarizes the technical details of this function.
Return Value: | Returns the position of the last occurrence of a string within another string, or FALSE if the string was not found. Remember that string positions start at 0, not 1. |
---|---|
Version: | PHP 5+ |
Syntax
The basic syntax of the strripos()
function is given with:
The following example shows the strripos()
function in action.
Example
Run this code »<?php
// Sample strings
$str = "The woodpeckers live in the woods.";
$substr = "The wood";
// Performing search
echo strripos($str, $substr);
?>
Parameters
The strripos()
function accepts the following parameters.
Parameter | Description |
---|---|
string | Required. Specifies the string to search in. |
search | Required. Specifies the string to search for. |
start | Optional. Specifies the position in the string to start searching from. If a negative value is specified, the search is performed right to left skipping the last start number of characters of the string and searching for the first occurrence of the search string. |
More Examples
Here're some more examples showing how strripos()
function actually works:
The following example uses the start parameter to perform searching.
Example
Run this code »<?php
// Performing search
echo strripos("The woodpeckers live in the woods.", "wood", 3);
?>
In the following example the start parameter is set to a negative value.
Example
Run this code »<?php
// Performing search
echo strripos("The woodpeckers live in the woods.", "wood", -10);
?>