Easiest and most efficient way to get data from URL using php? -


Solution?

Apparently there is not a fast way, I'm fine with that.


I am just learning php and I am trying to find out some good tips and tricks so that I do not get used to bad habit and waste time.

I am passing values ​​in a php script I am using $ _GET so that the URL looks like this:

/poll_results.php?Sports=tennis& ; Cat = Sports & amp; question = Pick + your + favorite + sports

Now I know how to accept those values ​​and keep them in this type of variable: < Pre> $ sports = $ _GET ['sports']; $ Cat = $ _GET ['Cat']; $ Question = $ _GET ['question'];

Super simple so far if I am passing 5-6, it can be disturbed and I do not like to type things for every single variable, this is the only reason. I know that there is a better way to do this. I have tried the list ($ var, $ var, $ var) = $ _GET , but it does not work just with an indexed array (I think).

I also tried Variable Variables like this:

  foreach (get $ $ as $ value) {$$ values ​​= $ value; Resize $$ value; }   

But he gave me a notice: undefined variable: value in poll_results.php at line 14. Line 14 is $$ values ​​= $ value. I do not know whether this is a big deal or not ... but I'm not turning off error reporting because I am in the process of creating a script. It does what I want to do ...

Any answer will be copied and paste in my question so that the next person will know: D

Thanks guys!

Your second bit of code is incorrect This should be

  foreach ($ Key = & gt; $ value as $ _GET) {$$ key = $ value; }   

If I understand your intentions, however, you are basically reinventing RegistryGlubels, which are ... .h

  foreach (array ('game', 'cat', etc.). If you want to get some variables, you can also do this. $ Key = $ _GET [$ key]; }   

which is unlikely to overwrite some important variables (whether it was due to accident or because there was a URL roaming around).

Comments