Results 1 to 2 of 2

Thread: Get the function name from the url?

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default Get the function name from the url?

    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:

    PHP Code:
    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!
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by alexjewell View Post
    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, 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!
    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •