0 votes
5.7k views
asked in General by (690 points)
php find exact match in string. not just contain words?

ie check if exact "India" inside a string, should not consider "Indiana" or something similiar.

How would you do that?

1 Answer

0 votes
answered by
Use the regex

$wildcard = "india";
$string = 'Bala Ji Karnal, India';

if (preg_match("/\b".$wildcard."\b/i", $string))
{
    echo "Got it!";
}
else
{
    echo "No match found!";
}

Related questions

+2 votes
2 answers 8.1k views
0 votes
2 answers 8.4k views
+1 vote
1 answer 1k views
+2 votes
1 answer 543 views
asked Feb 9, 2017 in General by Marc Lentin
0 votes
2 answers 707 views
asked Nov 24, 2016 in General by srinivasulu_yagnam (200 points)
...