I have been trying to get this work for ages. can anyone point me to a great tutorial or fill me in. One issue is this, I created my own php blog tools, and i think im having a date issue. but i scrapped my last rss try and im starting over.
creating rss feed with php mysql
Have you searched google?
i cant find an easy tutorial i keep finding partials not fulls
Here is the output of the rss.xml file I cant get the htmlentities to work. also something else is making it hard to validate any help?
<xml version="1.0" encoding="ISO-8859-1">
<rss version="2.0">
<channel>
<title>Corvine Design - Grand Rapids Web Design and Blog</title>
<description>A site dedicated to the work of Joel Leo, along with a weblog about my daily acitivities and ideas. Also contains a great image gallery.</description>
<link>http://www.corvinedesign.com/news.php</link>
<copyright>Copywrite 2004 Corvine Design</copyright>
<item>
<title><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>27</b><br />
</title>
<description><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>28</b><br />
</description>
<link />http://www.corvinedesign.com/permanent.php?post_id=265 <pubDate>Wed, 31 Dec 1969 16:33:25 PST</pubDate>
</item>
<item>
<title><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>27</b><br />
</title>
<description><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>28</b><br />
</description>
<link />http://www.corvinedesign.com/permanent.php?post_id=264 <pubDate>Wed, 31 Dec 1969 16:33:25 PST</pubDate>
</item>
<item>
<title><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>27</b><br />
</title>
<description><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>28</b><br />
</description>
<link />http://www.corvinedesign.com/permanent.php?post_id=263 <pubDate>Wed, 31 Dec 1969 16:33:25 PST</pubDate>
</item>
<item>
<title><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>27</b><br />
</title>
<description><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>28</b><br />
</description>
<link />http://www.corvinedesign.com/permanent.php?post_id=262 <pubDate>Wed, 31 Dec 1969 16:33:25 PST</pubDate>
</item>
<item>
<title><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>27</b><br />
</title>
<description><br />
<b>Warning</b>: htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>28</b><br />
</description>
<link />http://www.corvinedesign.com/permanent.php?post_id=261 <pubDate>Wed, 31 Dec 1969 16:33:25 PST</pubDate>
</item>
</channel>
</rss>
Generally when you are having problems with code you post the code so we can take a look at it...
Here...I don't even remember where I got this but it does the trick just fine...it's old cruncy stuff though that should probably get a rewrite...you'll probably need to write your own function for dealing with the time/date stuff...and adapt some stuff...
function makeRSS() {
global $conn,$config;
$qry = mysql_query ("SELECT file_name,title,pdate,text FROM blog WHERE mainmid='1' AND usid='$conn[id]' ORDER BY pdate DESC LIMIT 0,10");
$rs = mysql_fetch_array($qry);
$s = "";
$s .= "<?xml version=\"1.0\"?>\r\n";
$s .= "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" >\r\n";
// Build the channel tag
$s .= "<channel>\r\n";
$s .= "<title>$config[site_name]</title>\r\n";
$s .= "<link>$conn[site_url]</link>\r\n";
$s .= "<description>$config[sub_title]</description>\r\n";
$s .= "<dc:language>$config[lang]</dc:language>\r\n";
$s .= "<dc:creator>$conn[site_url]</dc:creator>\r\n";
$s .= "<dc:rights>Copyright 2005</dc:rights>\r\n";
//$s .= "<dc:date>2004-06-16T12:40:20</dc:date>\r\n";
do {
$s .= "<item>\r\n";
$s .= "<title>" . htmlspecialchars($rs['title']) . "</title>\r\n";
$s .= "<link>$conn[site_url]$rs[file_name]</link>\r\n";
$s .= "<description>" . htmlspecialchars($rs['text']) . "</description>\r\n";
$s .= "<dc:date>" . formatDater($rs['pdate']) . "</dc:date>\r\n";
$s .= "</item>\r\n";
} while($rs = mysql_fetch_array($qry));
// Add the closing rss tag and return the value
$s .= "</channel>\r\n";
$s .= "</rss>\r\n";
return $s;
}
// Output the generated RSS XML
header("Content-type: text/xml");
$xml = makeRSS(); echo $xml;
this is the error that I want to fix first.
htmlentities() expects parameter 2 to be long, string given in <b>/home/.waddlerheater/joeldleo/corvinedesign.com/rss.xml</b> on line <b>27</b>
This is the code :
<?php header('Content-type: text/xml'); ?>
<xml version="1.0" encoding="ISO-8859-1" />
<rss version="2.0">
<channel>
<title>Corvine Design - Grand Rapids Web Design and Blog</title>
<description>A site dedicated to the work of Joel Leo, along with a weblog about my daily acitivities and ideas. Also contains a great image gallery.</description>
<link />http://www.corvinedesign.com/news.php
<copyright>Copywrite 2004 Corvine Design</copyright>
<?php
$conn = mysql_connect("mysql.corvinedesign.com", "xxx", "xxx");
$db = mysql_select_db("corvinedesign"); ?>
<?php
$doGet= mysql_query("SELECT * FROM news ORDER BY post_date DESC LIMIT 5");
while($item=mysql_fetch_array($doGet))
{
$post_id=$item['post_id'];
$post_title=strip_tags($item["post_title"]);
$post_text=strip_tags($item["post_text"]);
$post_text=substr($post_text,0,150);
$pubDate=strftime("%a, %d %b %Y %T %Z",$item["post_date"]);
?>
<item>
<title><?php print htmlentities($post_title,'ENT_QUOTES');?></title>
<description><?php print htmlentities($post_text,'ENT_QUOTES'); ?></description>
<link />http://www.corvinedesign.com/permanent.php?post_id=<? print $post_id; ?>
<pubDate><?php print $pubDate;?></pubDate>
</item>
<?php } ?>
</channel>
</rss>
Perhaps?
<?php print htmlentities($post_text, ENT_QUOTES); ?>
When in doubt...read the manual...
Now my issue is with the date. For some reason they are all coming up as dec 1969
1969 means that it's not reading your info properly...I suggest you read the manual. This is a simple one...
vaaaska thanks for your help so far, I am new to this , not only that I have not touched php in a few months. Please accept my apology,
I have tried everything i could think of based on the manual
This is a blog program I created and when I started I used the date format of 2004-09-15 now trying to convert it to the date format rss nees I am having a hard time. Please help a newb like me?
You are close but you need to convert your date so that strftime understands it...I plucked this solution from Example 2 in the manual...
$item["post_date"] = "2004-09-15";
$pubDate = strftime("%a, %d %b %Y %T %Z", strtotime($item["post_date"]));
echo $pubDate;
Good luck...v