0 votes
8.9k views
in General by (1.3k 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
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 10.8k views
0 votes
1 answer 994 views
asked Oct 29, 2021 in General by anonymous
0 votes
2 answers 12.1k views
0 votes
1 answer 1.1k views
asked Jan 23, 2022 in General by Sarath
0 votes
1 answer 1.1k views
asked Oct 29, 2021 in General by anonymous
0 votes
1 answer 1.1k views
asked Oct 4, 2021 in General by Tester Testee (220 points)
...