View Full Version : LIKE function in PHP?
Colin F
07-27-2004, 12:11 PM
Hi
I'm trying to compare two var's.
In mySQL, I can do WHERE field1 LIKE %foo%
How can I do something similiar in PHP, to exchange this:
if ($field1 == $foo) { }
?
(hope that's understandable :ermm: )
mattster2002
07-27-2004, 01:14 PM
You could use Regex.
For example
<?php
if (eregi("foo", $field1)) {
echo "'$feild1' contains a 'foo' or 'FOO'!";
}
?>
Use the ereg funciton if you want to make it case sensitive
Is that what you mean?
Dean C
07-27-2004, 01:18 PM
You want to see if there's a substring with a string right?
E.g. if the word abracadabra contains the string cada ?
Colin F
07-27-2004, 01:30 PM
hmmm... now that you say it like that, actually... yes...
of course, stristr()
Thanks for giving me that kick I needed ;)
Dean C
07-27-2004, 09:34 PM
You're much better off using the strpos function :) It's a lot faster!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.