Simple and Effective Rotator

Discussion in 'PHP' started by jessecooper, Sep 9, 2007.

  1. #1
    Ok so I spent like 3 hours looking for an uber simple effective php rotating script... and really couldn't find any!

    What I needed was something that could rotate html randomly while being very small file wise.

    So i'll share it here.

    <?
    $banners = split("<!-- SPLIT -->", preg_replace("/<\?.*?\?>/", "", file_get_contents("/complete route to directory/rotatelist.txt")));
    
    echo $banners[rand(0,sizeof($banners) - 1)];
    ?>
    PHP:
    First you put the above in your index.php file or whatever...
    Then you create a rotatelist.txt file and include what ever info you need to be rotated (banners, img's, html).
    Just put a hard return and <!-- SPLIT --> in between whatever you want rotated.

    Again super simple and useful. and make sure to put the filepath from your root into the rotatelist.txt.
     
    jessecooper, Sep 9, 2007 IP
  2. livehybrid

    livehybrid Active Member

    Messages:
    100
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    Thanks alot :) Good one
     
    livehybrid, Sep 10, 2007 IP
  3. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    You could always just delimit each with a new line, then explode( "\r\n", $file_contents)
    (Important note: "\r\n" must be wrapped in " not ', otherwise the linebreak won't be considered a linebreak, just those literal charchters)

    Shaves a few bytes of your banners.txt too. :p
     
    Synchronium, Sep 10, 2007 IP
  4. affycons

    affycons Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I tried this and for me it simply rotates a text display of the file names I list in the text file rather than incorporating their respective code into the html that the php generates.

    Still useful for this purpose, but how do I get the file contents to be rotated?

    :cool:
     
    affycons, Oct 3, 2007 IP
  5. jessecooper

    jessecooper Peon

    Messages:
    793
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you have to put the actual code into the file... not the filenames then use the <!-- SPLIT --> and a hard return each time you want new stuff
     
    jessecooper, Oct 4, 2007 IP