EK Posted March 14, 2011 Share Posted March 14, 2011 I want to write a conditional statement like the following: if ($value = "300x") { however, I want this to work if x is changed to anything. So the conditional should work if the following is true: if ($value = "300dog") { or if ($value = "300cat") { How do I make it work as long as 300 is present regardless of what follows after. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/230648-help-writing-conditional-statement/ Share on other sites More sharing options...
abhi_madhani Posted March 14, 2011 Share Posted March 14, 2011 hi, try this solution <?php $paragraph = '300 had not been then, greece would not have been now'; $paragraph1 = 'if 300 had not been then, greece would not have been now'; $var1 = '300'; if (stripos($paragraph, $var1)=='0') { echo 'it works'; } else { echo 'it doesnt'; } ?> now try changing $paragraph with $paragraph1 in stripos. Regards, Link to comment https://forums.phpfreaks.com/topic/230648-help-writing-conditional-statement/#findComment-1187537 Share on other sites More sharing options...
EK Posted March 15, 2011 Author Share Posted March 15, 2011 Thanks for the help. Actually my $var1 needed to be a string, something like 300var So I changed if (stripos($paragraph, $var1)=='0') { to if (stripos($paragraph, $var1) !== false) { and it worked perfectly! Thanks! Link to comment https://forums.phpfreaks.com/topic/230648-help-writing-conditional-statement/#findComment-1187559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.