Solved

exact match in PHP

Posted on 2004-08-10
10
749 Views
Last Modified: 2012-05-05
is there any function to check "exact match" of string in PHP.
Mridul KK
0
Comment
Question by:mridulkk
10 Comments
 
LVL 10

Expert Comment

by:eeBlueShadow
Comment Utility
erm, yes

if($onestring == $twostring)
{
    // exact match
}
0
 
LVL 32

Expert Comment

by:ldbkutty
Comment Utility
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
 

Author Comment

by:mridulkk
Comment Utility
that i know..but can't i use something like "preg_match" etc.
0
 
LVL 7

Expert Comment

by:zac_charles
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Expert Comment

by:arantius
Comment Utility
What is your definition of an exact match?
0
 

Author Comment

by:mridulkk
Comment Utility
means ..word 'cool' should match only 'cool' & not 'coolly' or 'supercool' or 'wellcol'  !!!!
0
 
LVL 7

Expert Comment

by:zac_charles
Comment Utility
<?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
 
LVL 7

Accepted Solution

by:
zac_charles earned 20 total points
Comment Utility
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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now