Jump to content


parsing the xml

  • Please log in to reply
1 reply to this topic

#1 spellbinder

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 07 September 2006 - 07:06 AM

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



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

die("Cannot open file.");

@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>"

#2 btherl

  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 07 September 2006 - 07:15 AM

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users