Jump to content

Compare variable with multiple words


kvnirvana

Recommended Posts

I need to compare the variable $q to multiple words (the, wood, host). Tried to do it like this but it doesn’t work. So if one of these words appears it will echo “his” otherwise it will echo “her”

 

<TR><br><p style='font-family:verdana;font-size:150%;'>how many {$_GET['ber']},  {$_GET['nn']}  are "; If ($q == 'the') or ($q == ’wood’) or ($q == ’host’) 
{ 
Echo " his $q?</p>"; 
        } 
Else{ 
Echo " her $q?</p>"; 
}  

Link to comment
Share on other sites

That will work fine as long as you want the comparisons to be case sensitive. i.e. "wood" != "Wood".

 

If you need the comparison to be case insensitive you can do something similar to what you had before using strcasecmp()

 

 

if(strcasecmp($q, 'the')==0 || strcasecmp($q, 'wood')==0 || strcasecmp($q, 'host')==0)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.