January 13, 200917 yr Hi, I have a number of tips overlaying a website banner which are text. I want them to change at random everytime a user refreshes the page. Any ideas how to do this? I am using php. I know how to do this for images, but unsure how text based will work. Thanks
January 13, 200917 yr Theres plenty of examples on the internet, and a few different methods. Here's a very basic one. <?php $quotes[] = "This is a quote"; $quotes[] = "This is another"; $quotes[] = "quote 3"; $quotes[] = "quote 4"; $quotes[] = "quote 5"; $quotes[] = "quote 6"; srand ((double) microtime() * 1000000); $randomquote = rand(0,count($quotes)-1); echo "<p>" . $quotes[$randomquote] . "</p>"; ?>
January 13, 200917 yr Theres plenty of examples on the internet, and a few different methods. Here's a very basic one. <?php $quotes[] = "This is a quote"; $quotes[] = "This is another"; $quotes[] = "quote 3"; $quotes[] = "quote 4"; $quotes[] = "quote 5"; $quotes[] = "quote 6"; srand ((double) microtime() * 1000000); $randomquote = rand(0,count($quotes)-1); echo "<p>" . $quotes[$randomquote] . "</p>"; ?> This could come in handy Is there a way of adding HTML to; $quotes[] = "This is a quote"; $quotes[] = "This is another"; $quotes[] = "quote 3"; $quotes[] = "quote 4"; $quotes[] = "quote 5"; $quotes[] = "quote 6";
January 13, 200917 yr <?php $quotes[] = '<a href="#kapow">This is some html</a>'; $quotes[] = '<div id="html_box" style="border:5px solid blue; padding:5px;">This is a box with a blue border</div>'; $quotes[] = 'quote 3'; $quotes[] = 'quote 4'; $quotes[] = 'quote 5'; $quotes[] = 'quote 6'; srand ((double) microtime() * 1000000); $randomquote = rand(0,count($quotes)-1); echo '<p>' . $quotes[$randomquote] . '</p>'; ?> That would work. Just make sure you use alternate quotes to differentiate between php and html. Notice i changed the php quotes to ' and then for the html i've used "
Create an account or sign in to comment