• Afluence
  • Owaranai Kiss
  • Ryuu no Yume
  •            
  • Kyzumi Designs
  • Ssaffira Creation
  • Apply?

Site

  • Home Page
  • About the Site
  • Past Layouts
  • FAQ//Contact
  • Linkage
  • Joined
  • Credits & Resources
  • Terms of Use

For You

  • FAMILY
  • Give it 100%?
  • Info. Please!
  • The Four Wives
  • The Cab Driver
  • Philosophy
  • Tutorials

Designs

  • Icons
  • Pre-made Layouts
  • Textures
  • Transparent Images
  • Desktop Wallpapers

Media

  • Calendar Set
  • Emoticons
  • Photoshop Brushes
  • Photoshop Patterns
  • Photoshop Splash

Randomizing Content with PHP

  • ID: PHP - 15
  • Date Added: 2007-12-22
  • Category: PHP
  • Difficulty: Novice
  • Author: Rei
This tutorial will teach you how to randomize anything: images, links, paragraphs, texts using php. This is a very simple tutorial, and you can do this without any knowledge of php at all!

<?php
$filename = "random.txt";
$file = file($filename);

  srand((double)microtime()*1000000);
  while ($Random == "") {
  $Random = ereg_replace("\n","",$file[rand(0,count($file))]);
  }

  print "$Random";
?>
This is one way of doing this. You must create a file called random.txt, and insert anything you want. However, you must separate each link or value with a new line. This is a sample of a text page:
<a href="link.html" target=_blank>Akatsuki Designs</a>
<a href="link.html" target=_blank>Kyoukei</a>
<a href="link.html" target=_blank>JSound</a>
Quote 1
Quote 2
Quote 3
<img src="something.gif">
<img src="something.gif">
The second method is simpler, requires no .txt files, but you will define your random content within the php. This is recommended for when you don't have a lot of things to randomize:
<?php
$quotes[] = "Quote1";
$quotes[] = "Quote2";
$quotes[] = "Quote3";
$quotes[] = "Quote4";
$quotes[] = "Quote5";
$quotes[] = "Quote6";

srand ((double) microtime() * 1000000);
$randomquote = rand(0,count($quotes)-1);

echo " " . $quotes[$randomquote] . " ";
?>
You can modify $quotes[] = "Quote1"; to your heart's content =)

« back · clear ¦ reload · forward »
Akatsuki Designs © Rei [2006-2008]
eXTReMe Tracker
Akatsuki Designs © Rei [2006-2008]. Site, layout, and content © Rei. All rights reserved. Valid CSS and HTML
Fight Spam! | Spot a typing error? | HostTracker