Solved

exact match in PHP

Posted on 2004-08-10
10
751 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

19 Experts available now in Live!

Get 1:1 Help Now