Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.

Thread Tools Display Modes
Share |
Old 06-14-2008, 08:12 PM
LS5150 LS5150 is offline
Junior Member
Join Date: 06-03-08
Posts: 5
iTrader: 0 / 0%
Question Using %Like% operator in PHP for compare

I for the life of me, can't figure this out. I want to do a compare if a string has certain words in it then it should print a certain variable. The particular field I am wanting to compare from in my database may have other stuff in it, but I just want it to check to make sure it has three words. I just cannot figure out what in PHP is the equivalent to the %like% SQL command.

Here's what I have now, obviously the = doesn't work. Ideas?

if ($namerow['honors'] = "hall of fame") { $asterisk = "*"; } else { $asterisk = ""; }
That $namerow['honors'] has a lot more in it than just the words "hall of fame," but I just need the "if" command to check if those three words are there. I know this has to be simple, but I'm just missing it somehow.

Reply With Quote



Old 06-15-2008, 10:59 AM
Capo64 Capo64 is offline
Contributing Member
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
you can use the
stristr() function,

string stristr ( string $haystack , mixed $needle [, bool $before_needle ] )

if (stristr($namerow['honors'], 'hall of fame')) {
$asterisk = '*';
} else {
$asterisk = '';

or even more compact:

$asterisk = (stristr($namerow['honors'], 'hall of fame') ? '*' : '');

this is for case insensitive comparing. If you want it to only match hall of fame and not HaLL of FamE, use just strstr() (it's the same format)
Reply With Quote
Old 06-15-2008, 04:18 PM
LS5150 LS5150 is offline
Junior Member
Join Date: 06-03-08
Posts: 5
iTrader: 0 / 0%
Sweet, just tried it. Works great! Thanks!
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
site: operator, pages being dropped from googles index? wdman Google Forum 1 03-29-2008 08:43 PM
How come when u use an Operator , the outcome is different? crazyhorse Google Forum 4 07-25-2004 08:39 AM

V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory

All times are GMT -7. The time now is 06:45 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC