exact match in PHP

is there any function to check "exact match" of string in PHP.
Mridul KK
mridulkkAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
zac_charlesConnect With a Mentor Commented:
That one will print "A match was found" while:

<?php
if (preg_match("/\bcool\b/i",'you  are coolly haha')) {
   print "A match was found."; // match found
} else {
   print "A match was not found."; // no match found
}
?>

Will print "A match was not found" (because there is no 'cool' only 'coolly').

Zac Charles
0
 
eeBlueShadowCommented:
erm, yes

if($onestring == $twostring)
{
    // exact match
}
0
 
ldbkuttyCommented:
From PHP Manual:

 Example           Name                   Result
 ----------           -------                  ---------
 $a == $b           Equal          TRUE if $a is equal to $b.
 $a === $b       Identical      TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)  
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
mridulkkAuthor Commented:
that i know..but can't i use something like "preg_match" etc.
0
 
zac_charlesCommented:
php manual quote [http://au3.php.net/manual/en/function.preg-match.php]:

<?php
// The "i" after the pattern delimiter indicates a case-insensitive search
if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) {
   print "A match was found.";
} else {
   print "A match was not found.";
}
?>

This what you mean?
Zac Charles
0
 
arantiusCommented:
What is your definition of an exact match?
0
 
mridulkkAuthor Commented:
means ..word 'cool' should match only 'cool' & not 'coolly' or 'supercool' or 'wellcol'  !!!!
0
 
zac_charlesCommented:
<?php
if (preg_match("/\bcool\b/i",'you  are cool haha')) {
   print "A match was found."; // match found
} else {
   print "A match was not found."; // no match found
}
?>

Zac Charles
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.