SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: random include

Hybrid View

  1. #1
    SitePoint Evangelist j0n's Avatar
    Join Date
    Apr 2003
    Location
    uk
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    random include

    Hey, i am looking for a way to show a random php include.

    Any ideas ?

    Cheers, Jon

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    Michigan, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Edit:

    Skip my post, go down to the next one. It's a better solution.


    One method would be to build the include statement into a variable and eval it. For example, setup the variable $include_me. Have your includes have the same file name except for a number at the end.

    You end up with something like:
    PHP Code:
    $include_me "include(\"include$rand.inc\" );
    eval 
    $include_me
    Where $rand is a randomly generated integer within the range of files that you have.
    Last edited by Andy Tomaka; Jul 21, 2003 at 10:19.

  3. #3
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or, just to be nitpicky, for better performance, call the include directly:

    PHP Code:
    include("include$rand.inc"); 
    My name is Steve, and I'm a super-villian.

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    Michigan, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haha, nah, that's not to be nitpicky lieut_data. That's me being an idiot. I apologize for that. I had originally had a different idea to begin with and then realized it was much simpler with just putting the variable there...and forgot about not needing eval(). Thanks for pointing it out!

  5. #5
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    -- no worries, mate!

    Glad to help!
    My name is Steve, and I'm a super-villian.


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
  •