in php how to check word is exits

0 votes
asked Jun 23, 2013 in PHP by kalpana (3,995 points)
hi all

   in php how to check word is exits
commented Jun 23, 2013 by kalpana (3,995 points)
// Do the check
if (in_array($key, $sent))
    echo "Word found";
    echo "Word not found";

1 Answer

0 votes
answered Jun 24, 2013 by admin (8,135 points)


$needle = "to";
$haystack = "I go to school";

strpos() and stripos() method (stripos() is case insensitive):

if (strpos($haystack, $needle) !== false) echo "Found!";

strstr() and stristr() method (stristr is case insensitive):

if (strstr($haystack, $needle)) echo "Found!";

preg_match method (regular expressions, much more flexible but runs slower):