0 votes
1.5k views
asked in General by (580 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 4.4k views
0 votes
2 answers 3.5k views
+1 vote
1 answer 869 views
+2 votes
1 answer 474 views
asked Feb 8, 2017 in General by Marc Lentin
0 votes
2 answers 583 views
asked Nov 23, 2016 in General by srinivasulu_yagnam (200 points)
...