Jump to content

Archived

This topic is now archived and is closed to further replies.

spellbinder

parsing the xml

Recommended Posts

Hi, I'm new here and i'm still reading the tutorials but it's a bit complicated for me..
so i'm wondering if someone can check if my parsing is correct because i'm stuck in doing my assignments...
thanks in advance


<?php

$URL="http://www.linuxsig.net/project/todayrss.php";

$file = fopen($URL, 'r');

if(!$file)
die("Cannot open file.");

include("dbconnect.php");
@mysql_query("DELETE FROM 'today'", $db);

//read rss feed contents
$readfile = fread($file, 1000);
$searchfile = eregi("<item>(.*)</item>", $readfile, $array);
//place articles in array
$article = explode("<item>", $array[0]);
$counter = count($article);
echo "<table border='1'>";
echo "<th colspan='2'>MMU Lastest News</th>";

//loop to display all bulletins
for ($i=0; $i<count; $i++)
{
//fetch titles
ereg("<title>(.*)</title>", $article[i], $title);
//fetch categories
ereg("<category>(.*)</category>", $article[i], $category);
//fetch descriptions
ereg("<description>(.*)</description>", $article[i], $description);
//fetch links
ereg("<link>(.*)</link>", $article[i], $link);

echo "<tr><td>";
echo $title[1];
echo "</td><td>";
echo "<a href='$link[1]'\>$link[1]</a>";
echo "</td></tr>";
}

echo "</table>"
?>

Share this post


Link to post
Share on other sites
I get a 404 error on that URL.

Does your code work?  I'm unclear on what your question is.

It looks to me like your code will work, as long as there is only one title, category, description and link in each item.

There is no need to set $searchfile = eregi(...) if you aren't going to reference that variable later though.  You can just call eregi() the same way you call ereg() later in your code.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.