Jump to content

announcements.xml parsing via php?


senad

Recommended Posts

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.

Link to comment
Share on other sites

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>");
}
?>

Link to comment
Share on other sites

  • WHMCS CEO

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

Link to comment
Share on other sites

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. :shock: So the code can't work when it expecting the same password and user... :roll:

 

I'll fix that when I move it over...

 

Thanks again Matt.

 

Cheers,

 

Mike

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated