Forum Moderators: coopster

Message Too Old, No Replies

if statement wildcards

bit a a newbie here

         

GerBot

11:38 am on Mar 15, 2005 (gmt 0)

10+ Year Member



Hi Guys,
I have this:
$my_name = "someguy";

if ( $my_name == "someguy" ) {
echo "Your name is someguy!<br />";
}
echo "Welcome to my homepage!";

however I want the change this so that the script also matches when $my_name is also "someguy widget"or "widget someguy"
I want to allow for infinite possibilites so listing
"someguy widget" or "widget somguy" will not work

I tried reducing '==' to just '=' but I ended up matching absolutely everything.

>>>>>>>>>>>>>>>>>>>>EDIT>>>>>>>>>>>>>>>>>>>>

Sorry Guys just discovered the world of preg_match

if (preg_match('/someguy/', 'someguy widget'))
echo "Welcome to my homepage!";

coopster

12:52 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Glad you got it, GerBot.

As for the equal sign versus double equal sign, that is the difference between assignment and equality. Message #4 in this recent discussion offers some insight ...

[webmasterworld.com...]