Trying to include randomly-selected HTML blocks via php

Discussion in 'PHP' started by ststacytucker9, May 4, 2010.

  1. #1
    I'm working on a simple php/html page that wants to include an external html file selected at random on load, from a group of 3. And I need help! The code I have is:

    Code:

    <?php 
    
    $randContent = array_rand('gift1.html', 'gift2.html', 'gift3.html'); 
    include($randContent); 
    
    ?>
    PHP:
    It's not working. I have gift1.html, etc. stored in the same folder. On execute, this is the error message I get, pertaining to the code above:

    Warning: Wrong parameter count for array_rand() in /home/content/p/e/r/perfectseason/html/giving-dyn.php on line 258

    Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/p/e/r/perfectseason/html/giving-dyn.php on line 259

    The page is online at theperfectseason-dot-com-slash-giving-dyn.php in case my hero-helper wants to look at the entire source.
     
    ststacytucker9, May 4, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    it is because array_rand only accept paramete one as an array,
    rebuild your array to

    $pages = array('g1','g2','g3',etc..);
    $randContent = array_rand($pages);
     
    bartolay13, May 4, 2010 IP
  3. ststacytucker9

    ststacytucker9 Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for suggestion
     
    ststacytucker9, May 4, 2010 IP