PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jjdavis84
Forum Newbie
Posts: 2 Joined: Mon Jul 14, 2008 8:55 pm
Post
by jjdavis84 » Tue Jul 15, 2008 12:45 am
Does anyone have any suggestion on how to modify the following so it will pull the file names from an XML file so I can update the XML file instead of the PHP file? Hopefully that makes sense.
Code: Select all
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<?php
$files = array(
0 => 'test1.php',
1 => 'test2.php',
2 => 'test3.php'
);
$index = array_rand($files);
include($files[$index]);
?>
<body>
</body>
</html>
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Tue Jul 15, 2008 2:06 am
Well if you have SimpleXML available that is what it is ideally suited for, reading XML files.
Code: Select all
$xml = simplexml_load_file ('somefile.xml'); // Make sure it valid XML file or I think parser fails
Then you access elements like this:
jjdavis84
Forum Newbie
Posts: 2 Joined: Mon Jul 14, 2008 8:55 pm
Post
by jjdavis84 » Tue Jul 15, 2008 3:17 am
trying to learn as I go... what would the XML file be like? Could you explain it a little more... Thank you so much for your help.