Re: DB search and case sensitive comparison
| From: | Shawn McKenzie | Date: | Tue, 15 Jul 2008 14:55:24 +0000 |
| Subject: | Re: DB search and case sensitive comparison | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276839@lists.php.net to get a copy of this message | ||
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