laurierobey: (Lego Me)
On the site I'm working on for gneech.com, I'm going to have a box where I load a random quote from [livejournal.com profile] the_gneech's writing. I'm thinking of having the quotes in an XML file, generating a random number, then loading the quote from the XML file that has an ID that matches the random number.

This is the first bit of functionality I'm trying to write in PHP. This is what I have so far:

<?php
// generate a random number
$random_number = mt_rand(1, 3);

// set name of XML file
$file = "quotes.xml";
// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

// pull the quote that matches the random number
Edit: I think this might work.$quote = $xml->quote[$random_number]

//print the quote
print "$quote\n";
?>

The code I haven't come up with yet is the part where I say, "Give me the quote with the ID that matches the random number I generated earlier."

Anyone know how to do this? Anyone know if this is even possible?

Profile

laurierobey: (Default)
laurierobey

January 2013

S M T W T F S
  1 2 34 5
6 789101112
13141516171819
20212223242526
2728293031  

Syndicate

RSS Atom

Most Popular Tags

Page Summary

Style Credit

  • Style: Caturday - Orange Tabby for Heads Up by momijizuakmori

Expand Cut Tags

No cut tags
Page generated Oct. 19th, 2017 07:06 am
Powered by Dreamwidth Studios