pTutorial

New way to learn PHP function

PHP Strstr() function

Syntax

strstr(String, search text);

Parameter Description
String Any String (Required)
Search text Any text you want to search

Definition

It returns the first occurrence of search text to the end of String.

Usage

Strsrt function are used to find the first occurrence of sub string (second parameter) inside another string

Note: strstr() function is a case sensitive function.

Example of strstr function

<?php

$string = "understanding means transforming some text";

$txt = "some";

echo strstr($string, $txt);

?>

$string is a variable that hold the string and $txt is also a variable that you want to search in another string.

Pass both the variable into the strstr function according to the syntax.

Example

<?php

$a= strstr("understanding means transforming some text", "some");

if($a)
{
echo "Found";	
}
else
{
echo"Not found";
}
?>

Output

Found

You can pass strings directly into the strstr function as above shown in the example.

More example of strstr function

<?php

$string = "understanding means transforming some text";

$txt = "over";

echo strstr($string, $txt)."
"; ?>
.

Note: If search text is not found in String, FALSE is returned.

stristr() – case insensitive version of strstr() function

QUOTES OF THE DAY

A good beginning makes a good ending.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER