spfoonnewb Posted September 9, 2006 Share Posted September 9, 2006 Basically heres what I want:Its pretty self explanitory, except it obviously wont work, and thats why im here :)So basically if the query string has dothis=1&n=123 then I want the rest of the script to execute. So what it would do is get the rest of the query string and select only the numbers in it, as there is more to the string. Then I want the numbers to base whats posted, and if theres no numbers, or they dont exist just continue loading the page.[code]If @_$GET['dothis=1'];then execute the rest, else do nothing.--Get the query string@_$GET['QUERY STRING'];(ie. dothis=1&n=23 )Strip the numbers from it$str_replace(Get only the digits in the string) = $n;$n = $stripped;if $stripped = 22; echo 'blah for 22';if $stripped = 23 echo 'blah for 23';else 'Do nothing';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/ Share on other sites More sharing options...
tomfmason Posted September 9, 2006 Share Posted September 9, 2006 That code is a mess.lolWhy don't you just pass the query string in the number format. If you are useing [code=php:0]$_GET['QUERY STRING'][/code] then you cannot name it $n. If you want to use $n then you need to call it $n before it is passed to this script. Also, the correct form for ifs and else's is:[code=php:0]if ($something == $something2) { //do something}else{ //do something else}[/code]Good luck,Tom Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89105 Share on other sites More sharing options...
tleisher Posted September 9, 2006 Share Posted September 9, 2006 Maybe I'm being naive, but I have no idea why you are coding that way... I would do it like this:[code=php:0]<?phpif ((isset($_GET["dothis"]) && (isset($_GET["n"])) { # Bulk of code} else { echo "GET variables not loaded";}?>[/code]I have no idea what your trying to do though, are you trying to make it so that if they enter something that isn't a number, you want to strip the number? Because of SQL injection or something else? Explain a little more and I might be able to help further. Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89106 Share on other sites More sharing options...
spfoonnewb Posted September 9, 2006 Author Share Posted September 9, 2006 I wrote that in 3 minutes to make an example :DI need the script to pull the numbers out of the query string to display extra another page will already be includded by the index.php?do=this[b]&23=Yes[/b]So if the number is 23 I want to echo the information I put for 23 ...I can easily do:$_GET['QUERY STRING'] = $n;[b][u]I mostly just need a code to get only the numbers from the query string.[/u][/b] Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89113 Share on other sites More sharing options...
AndyB Posted September 9, 2006 Share Posted September 9, 2006 [quote author=spfoonnewb link=topic=107489.msg431370#msg431370 date=1157839929][b][u]I mostly just need a code to get only the numbers from the query string.[/u][/b][/quote]There isn't any method for 'only' getting numbers from a query string since you have no idea what's in the query string to start with. What I suspect you want to do is abstract information from the query string AND THEN test certain variables.[code]<?php// example of receiving thispage.php?this=6&that=wombat&the_other=123$this = $_GET['this']; // $this is 6$that = $_GET['that']; // $that is wombat$the_other = $_GET['the_other']; // $the_other is 123// NOW you can test the variables as you see fit...[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89121 Share on other sites More sharing options...
spfoonnewb Posted September 9, 2006 Author Share Posted September 9, 2006 I know exactly what will be in the query string, but the setup is:// example of receiving thispage.php?this=abc&that=wombat&[b]123=the_other[/b]Which is why I wanted to get the numbers. Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89123 Share on other sites More sharing options...
AndyB Posted September 9, 2006 Share Posted September 9, 2006 #1 - you have [b]no idea[/b] what's in the query string. Anybody could enter a query string in the browser window and send it to your page.#2 - since php variables [b]cannot[/b] start with a number, your example of &123=the_other is doomed to failure. Check the php manual for acceptable variable name constructs. Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89125 Share on other sites More sharing options...
kenrbnsn Posted September 9, 2006 Share Posted September 9, 2006 You could try something like this:[code]<?phpforeach($_GET as $key => $val) if(is_numeric($key)) {//// do the processing for a number// $the_number = $key;//// etc...// }else {//// do the other processing//}?>[/code]If you have control over the query string, I would suggest changing it to make processing easier.Ken Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89127 Share on other sites More sharing options...
corbin Posted September 10, 2006 Share Posted September 10, 2006 Or, if you want to only select the numerals from a query string, for example ?var1=d0qwe2 would be 02... you could try something like[code=php:0]$gVar = $_GET['gVar'];function numbers_only ($var) {$var2 = explode("", $var2);foreach($var2 as $k => $v) {if(is_numeric($v)) {$output .= $v;}}return $output;}[/code]If you put in that script $var1 = numbers_only($_GET['var1']); and you called to the script as http://yoursite.com/?var1=adf78adsfadsfasd576 $var1 would be 78576 Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89162 Share on other sites More sharing options...
Barand Posted September 10, 2006 Share Posted September 10, 2006 If you want a numbers_only() function thata ) uses the variable value that was passed to itb ) doesn't try to use explode illegally by passing an empty delimiterc ) was tested before postingtry[code]<?phpfunction numbers_only ($var) { $L = strlen($var); $output = ''; for ($i=0; $i<$L; $i++) { if(is_numeric($var{$i})) { $output .= $var{$i}; } } return $output;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20246-_get-echo/#findComment-89277 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.