PDA

View Full Version : Get the function name from the url?



alexjewell
06-17-2007, 11:28 PM
I'm working on a writings section in my website. What I want to do is the following:

Say the page is writing.php?writing=poem1. Now, I make $_GET['writing'] a variable, $writing, and use the following statement:



if($writing == 'poem1'){poem1();}


Now, as you can see, the piece itself is a function. There's a few reasons it has to be a function. Is it possible to set the function name to the variable $writing? As the site gets more complex, that would be ideal. For example: ($writing)(); or $writing(); or something?
Help!

mwinter
06-17-2007, 11:41 PM
Now, as you can see, the piece itself is a function. There's a few reasons it has to be a function. Is it possible to set the function name to the variable $writing? As the site gets more complex, that would be ideal. For example: ($writing)(); or $writing(); or something?

The latter will work fine.

See the manual entry regarding variable variables (http://uk.php.net/manual/en/language.variables.variable.php), particularly the contributed notes.

It goes without saying (but I'll say it anyway :)) that you need to be very careful to validate the input!