Wednesday, April 1, 2015

How to find a part of string in a string - PHP Snippet

How to find a part of string in a string - PHP Snippet

This php function searches a part of string inside a large string, return true if found.

function strinstr($find, $str){ 
$find = preg_quote($find);
if(preg_match('~'.$find.'~',$str)){
return TRUE;
}
return FALSE;
}
//exemple of use
$sStr = 'hello my name is billy bob joe.';

if(strinstr('ralph', $sStr))
echo 'found';
else
echo 'not found';
Disqus Comments