Re: DB search and case sensitive comparison

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Angelo Zanetti wrote:
Hi all,
I have a question and I can't seem to get around the problem or finding a
total solution.

I have a DB with a list of entries, one of the tables has fields and one of
the fields is called the lookup_string field.

This field is used to checkup values when users enter the site (explained
below).


So basically what happens is that the user will enter the site and I will
get their user agent from the $_SERVER variable.

What I want to do is to find out which entries in the DB are present in the
useragent string.

Eg:
lookup_string (in db): "Mozilla"

useragent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15)
Gecko/20080623 Firefox/2.0.0.15'

So what I did was I used the locate function in my mysql query which gives
me the correct result set.

Now what I need to do is to ensure that the lookup_string is in the
useragent string and the CASE is the same: IE: Mozilla and not MOZILLA or
mozilla etc...

I am using the following If (however it fails because its part of the
useragent string and not the whole complete string therefore providing a
mismatch).

if(strcmp($userAgent, $lookup_string)==0){

//matches
}
Else
{

//doesn't match
}
	
Which way could I accomplish searching for the lookup_string in the
useragent and that it's the correct case?

Thanks in advance.

Angelo




strpos(), ereg() or preg_match() should work, take your pick. strpos() most likely faster for this simple match.

if (strpos($userAgent, $lookup_string) !== false) {
    //matches
} else {
    //no matchy matchy
}

-Shawn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux