Jump to content

Archived

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

gardan06

creating an RSS .xml file using PHP

Recommended Posts

i'm asked to do a program where user could make their own articles and convert it into an RSS Feed. the problem ive had is that when i use fopen("test.xml","w") and an XML file is created, its contents does contain the script you usually see in an RSS XML Feed but it doesnt output like an RSS Feed, but rather generates this error: "Parse error: parse error, unexpected T_STRING in C:\Program Files\xampp\htdocs\aaaa.xml on line 1"

this is my script:[quote]<?
$link1 = "http://radio.weblogs.com/0001011/";
$link2 = "http://radio.weblogs.com/0001011/2005/11/27.html#a11433";
$link3 = "http://scobleizer.wordpress.com/";
$link4 = "http://scobleizer.wordpress.com/feed/";
$link5 = "http://radio.weblogs.com/0001011/2005/11/27.html#a11433";
$link6 = "http://scoblecomments2.scripting.com/comments?u=1011&amp;p=11433&amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001011%2F2005%2F11%2F27.html%23a11433";
$text = "<?xml version=\"1.0\" ?>\r\n";
$text .= "<rss version=\"2.0\">\r\n";
$text .= "<channel>\r\n";
$text .= "<title>Scobleizer: Microsoft Geek Blogger</title>\r\n";
$text .= "<link>".$link1."</link>\r\n";
$text .= "<description>Robert Scoble\'s look at geek and Microsoft life.</description>\r\n";
$text .= "<language>en-us</language>\r\n";
$text .= "<copyright>Copyright 2005 Robert Scoble</copyright>\r\n";
$text .= "<item>\r\n";
$text .= "<title>PLEASE SUBSCRIBE TO MY NEW BLOG</title>\r\n";
$text .= "<link>".$link2."</link>\r\n";
$text .= "<description><p>Hello, we know you\'re still subscribed to this blog (9,000 of you are on Bloglines, for instance). So, please unsubscribe from this blog and come over and visit me in my new home at <a href=\"".$link3."\">".$link3."</a></p> <p>My new RSS feed is here: <a href=\"".$link4."\">".$link4."</a></p> <p>I have permanently moved over there, so please do come and visit!</p></description>\r\n";
$text .= "<guid>".$link5."</guid>\r\n";
$text .= "<pubDate>Sun, 27 Nov 2005 13:44:16 GMT</pubDate>\r\n";
$text .= "<comments>".$link6."</comments>\r\n";
$text .= "</item>\r\n";
$text .= "</channel>\r\n";
$text .= "</rss>";
if ($fp = fopen("aaaa.xml","w")) {
fwrite($fp,$text);
fclose($fp);
echo "XML has been written.  <a href=\"aaaa.xml\">View the XML.</a>";
} else {
echo "could not save";
}
?>[/quote]

what'ts wrong with my script?

Share this post


Link to post
Share on other sites
See if this works for you:

[code]<?php

$link1 = "http://radio.weblogs.com/0001011/";
$link2 = "http://radio.weblogs.com/0001011/2005/11/27.html#a11433";
$link3 = "http://scobleizer.wordpress.com/";
$link4 = "http://scobleizer.wordpress.com/feed/";
$link5 = "http://radio.weblogs.com/0001011/2005/11/27.html#a11433";
$link6 = "http://scoblecomments2.scripting.com/comments?u=1011&amp;p=11433&amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001011%2F2005%2F11%2F27.html%23a11433";

$text = '
<?xml version="1.0" ?>
<rss version="2.0">
<channel>
<title>Scobleizer: Microsoft Geek Blogger</title>
<link>' . $link1 . '</link>
<description>Robert Scoble\'s look at geek and Microsoft life.</description>
<language>en-us</language>
<copyright>Copyright 2005 Robert Scoble</copyright>
<item>
<title>PLEASE SUBSCRIBE TO MY NEW BLOG</title>
<link>' . $link2 . '</link>
<description>
<p>
Hello, we know you\'re still subscribed to this blog (9,000 of you are on Bloglines, for instance).
So, please unsubscribe from this blog and come over and visit me in my new home at <a href="' . $link3 . '">' . $link3 . '</a>
</p>
<p>
My new RSS feed is here: <a href="' . $link4 . '">' . $link4 . '</a>
</p>
<p>I have permanently moved over there, so please do come and visit!</p>
</description>
<guid>' . $link5 . '</guid>
<pubDate>Sun, 27 Nov 2005 13:44:16 GMT</pubDate>
<comments>' . $link6 . '</comments>
</item>
</channel>
</rss>';

if ($fp = fopen("aaaa.xml","w")) {
fwrite($fp,$text);
fclose($fp);
echo "XML has been written.  <a href=\"aaaa.xml\">View the XML.</a>";
} else {
echo "could not save";
}
?>[/code]

Share this post


Link to post
Share on other sites
it also didnt work, but it wouldnt matter now coz ive finally made it work. thanks anyway

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.