Image

Imagexerode wrote in Imagephp_dev 😏pensive

Listens: scrap.edx - phase lock

Problems with writing an XML file

I'm trying to write an XML export of the last 10 blog entries stored as HTML in a MySQL database.


$fp = fopen( $_SERVER[ 'DOCUMENT_ROOT' ]."/blog/export/feed.xml", "w" );
fwrite( $fp, "<?xml version='1.0' encoding='iso-8859-1' ?>\n<rss version=\"2.0\">\n<channel>\n\t<title>xerode.net</title>\n\t<link>http://www.xerode.net/blog/</link>\n\t<description>the public blog of a bored 21-year-old \"cyberpunk\" stumbling through metropolitan life</description>\n" );
fwrite( $fp, "\t<lastBuildDate>".date( "r", time() )."</lastBuildDate>\n" );
fwrite( $fp, "\t<generator>xerode.net</generator>\n\t<image>\n\t\t<url>http://www.xerode.net/blog/export/mugshot.jpg</url>\n\t\t<title>xerode mugshot</title>\n\t\t<link>http://www.xerode.net/blog/</link>\n\t\t<width>100</width>\n\t\t<height>100</height>\n\t</image>\n" );

$query = mysql_query( "SELECT * FROM blog ORDER BY blg_time DESC LIMIT 10", connect_to_db( ) );

while( $results = mysql_fetch_array( $query ) )
{
	fwrite( $fp, "<item>\n\t<guid isPermaLink=\"true\">http://www.xerode.net/blog/entry/".$results[ 'blg_id' ]."</guid>\n" );
	fwrite( $fp, "\t<pubDate>".date( "r", $results[ 'blg_time' ] )."</pubDate>\n" );
	fwrite( $fp, "\t<title>".html_entity_decode( strip_tags( stripslashes( $results[ 'blg_title' ] ) ) )."</title>\n\t<link>http://www.xerode.net/blog/entry/".$results[ 'blg_id' ]."</link>\n" );
	fwrite( $fp, "\t<description>".html_entity_decode( stripslashes( $results[ 'blg_text' ] ) )."</description>\n</item>\n" );
}

fwrite( $fp, "\n</channel>\n</rss>\n" );
fclose( $fp );



It seems fine until its syndicated through LJ, when all the HTML tags are stripped from the main text (I purposely strip them from the title). The tags are written in the original XML document, but with superfluous line breaks thrown in.

I'm guessing this is due to html_entity_decode. I tried

html_entity_decode( stripslashes( $results[ 'blg_title' ] ), ENT_COMPAT, UTF-8 )

to encode it as UTF-8 but that came up with this error:

Notice: Use of undefined constant UTF - assumed 'UTF' in /www/xerode.net/html/admin/rebuild_xml.php on line 15

Warning: html_entity_decode(): charset `-8' not supported, assuming iso-8859-1 in /www/xerode.net/html/admin/rebuild_xml.php on line 15


Does anyone have any ideas where I'm going wrong? I'd appreciate the help.