Jump to content

Rotating php insert text


michaelsacca

Recommended Posts

If you aren't aiming for a database approach (which in that case the above will work just great), u can use:

 

Array Approach

<?php
$names = array('php', 'mysql', 'html', 'xml', 'javascript'); //the array that stores all the names
$rand = rand(0, count($names) - 1); //generate a random index from 0 to the number of array items - 1
echo $names[$rand];
?>

 

or a file approach, supposing u have your text names comma separated in names.txt. The text file should look like: "php,mysql,html,xml,javascript"

<?php
$names = explode(',', file_get_contents('names.txt')); //get file content of 'names.txt' and explode the comma to pass all the names in an array
$rand = rand(0, count($names) - 1); //generate a random index, same concept as the above snippet
echo $names[$rand];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.