You can also use
strstr() php function for find whether the given input string is available or not.
Code:
<?php
$str="hai this is new world";
$pos=strstr($str,"this");
if($pos==false)
{
echo "search string not found";
}
else
{
echo "the search string found in position".$pos;
}
?>
It returns the portion of string, or
FALSE if needle is not found.
This function is case-sensitive. For
case-insensitive searches, use
stristr().
The equivalent function for search whether a particular character or substring exists within a string in
Javascript is,
indexOf().
The
indexOf() function allows you to search whether a particular character or substring exists within a string, if so , where the first character of the character/substring is located.
If no match is found, "-1" is returned instead. See below code.
Code:
var str="hai this is new world"
if (str.indexOf("hai")!=-1)
alert("hai is in there!")
Anbarasan k