climbjm Posted December 5, 2007 Share Posted December 5, 2007 Is there a way to make this even smaller or run even faster? I have another page that send a text fields input to this page. The name/id of that text field is "Question". <?php if(eregi("bb",$_POST["Question"])) echo("2B"); else echo("!2B"); ?> I'd like to make it as small as possible. I will be turning it into a bumper sticker eventually. Aiming for <4 lines. (feel free to make your own bumper stickers too) Quote Link to comment Share on other sites More sharing options...
utahcon Posted December 5, 2007 Share Posted December 5, 2007 if you can drop the eregi you can do: $answer = ($_POST['Question'] == 'bb') ? '2B' : "!2B'; echo $answer You may even be valid with: $answer = (eregi('bb',$_POST['Question'])) ? '2B' : "!2B'; echo $answer Quote Link to comment Share on other sites More sharing options...
Orio Posted December 5, 2007 Share Posted December 5, 2007 strpos() can do the job here, and it's much faster. The number of lines doesn't really matter... You can do it in 1 line: <?php echo (strpos($_POST['Question'],"bb") !== FALSE) ? "2B" : "!2B"; ?> Orio. Quote Link to comment Share on other sites More sharing options...
Orio Posted December 5, 2007 Share Posted December 5, 2007 if you can drop the eregi you can do: $answer = ($_POST['Question'] == 'bb') ? '2B' : "!2B'; echo $answer That doesn't do the job... He wants to know if "bb" is present in the string, the regex isn't "^bb$". Orio. Quote Link to comment Share on other sites More sharing options...
climbjm Posted December 5, 2007 Author Share Posted December 5, 2007 Awesome, Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.