0 votes
8.5k 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.3k views
0 votes
1 answer 593 views
asked Oct 29, 2021 in General by anonymous
0 votes
2 answers 11.6k views
0 votes
1 answer 649 views
asked Jan 23, 2022 in General by Sarath
0 votes
1 answer 603 views
asked Oct 29, 2021 in General by anonymous
0 votes
1 answer 605 views
asked Oct 4, 2021 in General by Tester Testee (220 points)
...