Results 1 to 3 of 3

Thread: specific syntax question -- variable function names

  1. #1
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default specific syntax question -- variable function names

    These aren't related to a particular problem, but would save me time in the future (and with old scripts) if there's a way to use them.


    As with variable variables, can you have variable functions?
    For example, it's annoying to check "if jpeg, ... imagecreatefromJPEG... if gif..."
    Is there a way to do "imagecreatefrom$imgtype"?
    That's wrong, I know, but is there a correct way?
    Hmm.... maybe the eval function if that was stored as a string. Better way, though?




    Y'know... I had another semi-unrelated question and I can't remember it now. I'll post when I do, I guess.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes.
    I'm not entirely sure if you can do imgCreateFrom$imgtype, but you can do:
    Code:
    $imgfunc = "imageCreateFromJPEG";
    $imgfunc($file);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ok.
    So...

    PHP Code:
    $imgfunc "imageCreateFrom".strtoupper($filetype);
    $imgfunc($file); 
    Right?

    thanks
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •