how can i display a random title for my website? i know there is a way, and ive seen it done, but does anyone know how its done?
thanks...
| SitePoint Sponsor |
how can i display a random title for my website? i know there is a way, and ive seen it done, but does anyone know how its done?
thanks...

Java should be able to do it. Try javascripts.com.




You mean JavaScript.Originally posted by seanlivo81
Java should be able to do it.
How about this:
Code:... <head> <script type="text/javascript"> var titles = new Array( 'one', 'two', 'three'); var title = titles[parseInt(Math.random() * titles.length)]; document.write('<title>' + title + '</title>'); </script> </head> ...



Or you could do a server side solution using PHP:
This requires your web host to support PHP. Also, you will probably have to name your file with a .php extension.PHP Code:<html>
<head>
<title><?php
$titles = array();
$titles[] = "Possible Title 1";
$titles[] = "Possible Title 2";
$titles[] = "Etc. Etc.";
srand ((float) microtime() * 10000000); // Seed the random number generator
echo $titles[array_rand($titles)]; // Pick a random item from the array and output it
?></title>
</head>
<body>
</body>
</html>
thanks randem, that helped...
Bookmarks