Jump to content

parsing the xml


spellbinder

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>"
?>
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

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.