Jump to content


Photo

creating an RSS .xml file using PHP


  • Please log in to reply
3 replies to this topic

#1 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 28 August 2006 - 09:10 PM

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:

<?
$link1 = "http://radio.weblogs....com/0001011/";
$link2 = "http://radio.weblogs...7.html#a11433";
$link3 = "http://scobleizer.wo...ordpress.com/";
$link4 = "http://scobleizer.wo...ess.com/feed/";
$link5 = "http://radio.weblogs...7.html#a11433";
$link6 = "http://scoblecomment...7.html#a11433";
$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";
}
?>


what'ts wrong with my script?

#2 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 28 August 2006 - 09:27 PM

pls help..

#3 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 09:57 PM

See if this works for you:

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


#4 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 30 August 2006 - 06:50 PM

it also didnt work, but it wouldnt matter now coz ive finally made it work. thanks anyway




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users