I have a page that has url.php?n= If a person types in 1 2 3 4 5 then I need it to echo out the word of the number they typed
<?php if (isset($_GET['n'])) { for ($i=0;$i<=(strlen($_GET['n'])-1);$i++) { $character = substr($_GET['n'], $i, 1); if (strstr("01234567890",$character)) { switch ($character) { case 0: echo "zero"; break; case 1: echo "one "; break; case 2: echo "two "; break; case 3: echo "three "; break; case 4: echo "four "; break; case 5: echo "five "; break; case 6: echo "six "; break; case 7: echo "seven "; break; case 8: echo "eight "; break; case 9: echo "nine "; break; } } } } ?> <FORM method="GET" action=""> <input name="n" type="text" /> - <input name="submit" type="submit" value="Submit" /> </FORM> PHP:
Yes, Synchronium is right, each variable of the query string (after ? mark) is accessible by GET request. For example if you have url.php?a=1&b=2&c=3&d=pofapdopfosd then you will have a value for $_GET['a'], $_GET['b'], $_GET['c'] and $_GET['d'] Bind, doing something like $numbers=array('zero', 'one', 'two', 'three', ...) echo $numbers[$_GET['n']]; PHP: would have been simpler, but your solution is good!
agreed, but still have to parse for each charactor - strlen()+substr() - unless only one number is allowed per form submit. here they are combined if anyone is interested: <?php $numname = Array("zero ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine "); if (isset($_GET['n'])) { for ($i=0;$i<=(strlen($_GET['n'])-1);$i++) { $character = substr($_GET['n'], $i, 1); if (strstr("01234567890",$character)) { echo $numname[$character]; } } } ?> <FORM method="GET" action=""> <input name="n" type="text" /> - <input name="submit" type="submit" value="Submit" /> </FORM> PHP: