Re: That crazy IF command!

From: Date: Sun, 03 Apr 2005 20:00:11 +0000
Subject: Re: That crazy IF command!
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-39106@lists.php.net to get a copy of this message
* Ron Piggott <ron.php@actsministries.org>: > $query_holder="the big fat cow made lots of milk today"; > > are you able to use the if command to see if the words "big fat" are part of > that phrase? > > What would the syntax be? Depends on if you're trying to search the string with PHP or in your database. In PHP, you'd use one of the following: if (strpos($query_holder, "big fat")) { // found } if (preg_match('/big fat/i', $query_holder)) { // found // the '/i' means case insensitive, which would be one case // where you want to use a preg_match here instead of strpos } In SQL, you'd use: SELECT * FROM table WHERE field LIKE '%big fat%' In MySQL, the LIKE modifier is case insensitive; I'm not sure about other RDBMS. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:matthew@garden.org | http://vermontbotanical.org

« previous php.db (#39106) next »