?
Solved

exact match in PHP

Posted on 2004-08-10
10
Medium Priority
?
783 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 80 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

770 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