senad Posted June 24, 2008 Share Posted June 24, 2008 I'm trying to parse and display xml announcements on my front page. I've coded the following in: <?php /* load a xml file to memory & parse it */ $xml_file = file_get_contents("https://manage.pingpros.com/announcements.xml"); $xml = simplexml_load_string($xml_file); /* We are done, output time */ foreach ($xml->item as $msg) { echo("<a href='{$msg->link}'->{$msg->title}</a> <br />{$msg->description}<hr />"); } ?> However nothing is showing. Am I missing something here or shouldn't simplexml_load_string work without any flaws here? PHP Version 5.2.6 Simplexml support enabled Revision $Revision: 1.151.2.22.2.39 $ Schema support enabled Any help would greatly be appreciated. 0 Quote Link to comment Share on other sites More sharing options...
BAJI26 Posted June 24, 2008 Share Posted June 24, 2008 Wouldn't it be easier to add this to your page: <?php [color=red]include("support/dbconnect.php"); include("support/includes/functions.php");[/color] $query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,3"; $result = mysql_query($query); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; $date = $data["date"]; $title = $data["title"]; $announcement = $data["announcement"]; $date = fromMySQLDate($date); echo("<p><font color=#cccccc>$date</font> - <b>$title</b><br>$announcement</p>"); } ?> 0 Quote Link to comment Share on other sites More sharing options...
Austdata Posted June 25, 2008 Share Posted June 25, 2008 I'm trying to do a similar thing but I didn't think I could use PHP code in XHTML 1.0 document. Is it possible to put PHP code in an XHTML 1.0 document? Cheers, Mike 0 Quote Link to comment Share on other sites More sharing options...
Austdata Posted June 25, 2008 Share Posted June 25, 2008 Apparently it can be done. Dutchnet posted a response here but it's clearly not as simple as I thought. The code I have is almost identical to BAJI26's example but it displays nothing when I tested it. 0 Quote Link to comment Share on other sites More sharing options...
Austdata Posted June 25, 2008 Share Posted June 25, 2008 Went away to get the example but took longer than fifteen minutes: http://www.a1hosting.com.au/test.html It shows a little text under the news heading, which is where I'd like to put it and replace the hard coded stuff I have so far. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS CEO Matt Posted June 25, 2008 WHMCS CEO Share Posted June 25, 2008 XHTML is an HTML markup language. PHP is the server side language. So you can use PHP in a file with XHTML markup - but to execute PHP code the file needs to have a .php extension - simply change test.html to test.php Matt 0 Quote Link to comment Share on other sites More sharing options...
Drac0 Posted June 25, 2008 Share Posted June 25, 2008 Although, if you have access to your httpd.conf file, you can use AddType to allow php code to be imbedded in a .html or .htm file as well. AddType application/x-httpd-php .html .htm 0 Quote Link to comment Share on other sites More sharing options...
Austdata Posted June 25, 2008 Share Posted June 25, 2008 Hey, that's terrific. I have a whole bunch of errors there now. I have something to work with! Thanks Matt. Cheers, Mike 0 Quote Link to comment Share on other sites More sharing options...
Austdata Posted June 27, 2008 Share Posted June 27, 2008 Hey, that's terrific. I have a whole bunch of errors there now. I have something to work with! Thanks Matt. I worked out what the errors were, I'm developing the new site on my existing server. So the code can't work when it expecting the same password and user... I'll fix that when I move it over... Thanks again Matt. Cheers, Mike 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.