The most direct and simplest answer is to use the php function strstr and strpos
For example:
strstr
$a = “what is the cost of property insurance?”;
if (strstr($a, “insurance”))
{
echo “insurance was found in the string”;
}
strpos
As per the php documentation, there’s a better function to use apart from strstr, and that’s strpos (case sensitive) or stripos (case insensitive)
$a = “what is the cost of property insurance?”;
if (strpos($a, “insurance”)!==false)
{
echo “insurance was found in the string”;
}
Notice that the test operator used in the if condition is !== (not !=)
Leave a Reply