Solved

exact match in PHP

Posted on 2004-08-10
10
766 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
ID: 11763570
erm, yes

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

Expert Comment

by:ldbkutty
ID: 11763713
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
ID: 11769680
that i know..but can't i use something like "preg_match" etc.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 7

Expert Comment

by:zac_charles
ID: 11770893
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
 
LVL 18

Expert Comment

by:arantius
ID: 11785348
What is your definition of an exact match?
0
 

Author Comment

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

Expert Comment

by:zac_charles
ID: 11798882
<?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
ID: 11798888
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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.

733 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