Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Randomise a paragragph of text

Featured Replies

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

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>"; 

?>

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";

<?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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.