String Search

1) strpos or stripos— strpos find the position of firstoccurance of string and
returns false if string is not found. String position starts with 0 so
dont compare with 0 for finding string

$a = 'How arEd you?';
if(strpos($a,'are')!==false)
{
echo "string found";
}
// strpos is case sensitive. Use stripos() for case insensitive

2) preg_match()
//matches regular expression with a string

$a = 'How are you?';

if (preg_match('/are/i',$a)) //here i is for case insensitive
    echo 'true';

// output->true

but below output will also be true
$a = 'How ffare you?';

if (preg_match('/are/i',$a))
    echo 'true';
// output->true

// so we can use a boundary limit character of regular expression \b

$a = 'How are you?';

if (preg_match('/\bare\b/i',$a))
    echo 'true';
// output->true

3) strstr() and stristr()
//search a string and returns rest part of the string

$a = 'How are you?';

echo strstr($a,'are');
//output-- are you?

$a = 'How are you?';

echo strstr($a,'are',true);
//output-- How ?

but strstr does not check if its a single word it also searches string
within a word. So it is not correct method for searching

$a = 'How areee you?';

echo strstr($a,'are');
//output-- areee you?