Php Randomise Title

Any help regarding any computer based programming language (non serverside) can be requested and recieved here.
Locked
anish
Posts: 353
Joined: Fri Apr 27, 2007 12:34 pm
Contact:

Php Randomise Title

Post by anish »

PHP - Randomize Web Title with the rand function...

Define the variables numbers
we start at number 0
[PHP]<?php
$title[0] = "Web title 0"; // Title 0
$title[1] = "Web title 1"; // Title 1
$title[2] = "Web title 2"; // Title 2
$title[3] = "Web title 3"; // Title 3
$title[4] = "Web title 4"; // Title 4
?>[/PHP]

now we use the rand() function to get a randomize the web title.
rand(0, 4) means
we start at 0 and end at 4
i can get 0,1,2,3,4 one of those. It depends how many arrays you have

[PHP]<?
// get a random number
$randomize = rand(0, 4); // Change four to how many arrays you have
echo ($title[$randomize]);
?>
see it in action.
++++++++++++++++++++
<?php
$title[0] = "Web title 0"; // Title 0
$title[1] = "Web title 1"; // Title 1
$title[2] = "Web title 2"; // Title 2
$title[3] = "Web title 3"; // Title 3
$title[4] = "Web title 4"; // Title 4

// get a random number
$randomize = rand(0, 4); // Change four to how many arrays you have

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo ($title[$randomize]); ?></title>
</head>

<body>
Just a simple PHP tut
</body>
</html>[/PHP]


Locked