String Functions
Advertisements

PHP stripos() Function

Topic: PHP String ReferencePrev|Next

Description

The stripos() function finds the position of the first occurrence of a string inside another string.

This function is case-insensitive. For case-sensitive searches, use the strpos() function.

The following table summarizes the technical details of this function.

Return Value: Returns the position of the first 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 stripos() function is given with:

stripos(string, search, start);

The following example shows the stripos() function in action.

<?php
// Sample strings
$str = "The woodpeckers live in the woods.";
$substr = "the wood";

// Performing search
echo stripos($str, $substr);
?>

Parameters

The stripos() 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 it is negative, the search will start this number of characters counted from the end of the string.

More Examples

Here're some more examples showing how stripos() function actually works:

The following example uses the start parameter to perform searching.

<?php
// Performing search
echo stripos("The woodpeckers live in the woods.", "wood", 3); 
?>

In the following example the start parameter is set to a negative value.

<?php
// Performing search
echo stripos("The woodpeckers live in the woods.", "wood", -10);
?>
Advertisements
Bootstrap UI Design Templates