<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>kill the radio &#187; xml</title>
	<atom:link href="http://blog.killtheradio.net/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.killtheradio.net</link>
	<description>or die trying</description>
	<lastBuildDate>Thu, 15 Dec 2011 20:21:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to convert HTML named entities to numbered entities in PHP</title>
		<link>http://blog.killtheradio.net/how-tos/how-to-convert-html-named-entities-to-numbered-entities-in-php/</link>
		<comments>http://blog.killtheradio.net/how-tos/how-to-convert-html-named-entities-to-numbered-entities-in-php/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 05:40:12 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[How to's]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.killtheradio.net/?p=294</guid>
		<description><![CDATA[I recently (read: today) had an obnoxious problem: I&#8217;m writing some code for creating an ATOM feed, and kept getting errors about entity-escaped values. Namely, things like &#38;rsquo;, &#38;bull;, etc. Even written as entities, Opera and IE7 did not recognize them. I read somewhere that it was necessary to convert the named entities to numbered [...]]]></description>
			<content:encoded><![CDATA[<p>I recently (read: today) had an obnoxious problem: I&#8217;m writing some code for creating an ATOM feed, and kept getting errors about entity-escaped values. Namely, things like &amp;rsquo;, &amp;bull;, etc. Even written as entities, Opera and IE7 did not recognize them. I read somewhere that it was necessary to convert the named entities to numbered entities. Great.</p>
<p>Well, PHP doesn&#8217;t have a native function for this. Why, I do not know&#8230;there seems to be functions for many other things, and adding an argument to htmlentities that returns numbered entities would seem easy enough. Either way, I wrote a quick function that takes the htmlentities translation table, adds any <span style="text-decoration: underline;">missing values</span> that are not in the translation table, and runs the conversion to numbered entities. Check it:</p>
<pre>
function htmlentities_numbered($string)
{
	$table	=	get_html_translation_table(HTML_ENTITIES);
	$trans	=	array();
	foreach($table as $char => $ent)
	{
		$trans[$ent]	=	'&#'. ord($char) .';';
	}

	$trans['&amp;euro;']	=	'&amp;#8364;';
	$trans['&amp;sbquo;']	=	'&amp;#8218;';
	$trans['&amp;fnof;']	=	'&amp;#402;';
	$trans['&amp;bdquo;']	=	'&amp;#8222;';
	$trans['&amp;hellip;']	=	'&amp;#8230;';
	$trans['&amp;dagger;']	=	'&amp;#8224;';
	$trans['&amp;Dagger;']	=	'&amp;#8225;';
	$trans['&amp;circ;']	=	'&amp;#710;';
	$trans['&amp;permil;']	=	'&amp;#8240;';
	$trans['&amp;Scaron;']	=	'&amp;#352;';
	$trans['&amp;lsaquo;']	=	'&amp;#8249;';
	$trans['&amp;OElig;']	=	'&amp;#338;';
	$trans['&amp;lsquo;']	=	'&amp;#8216;';
	$trans['&amp;rsquo;']	=	'&amp;#8217;';
	$trans['&amp;ldquo;']	=	'&amp;#8220;';
	$trans['&amp;rdquo;']	=	'&amp;#8221;';
	$trans['&amp;bull;']	=	'&amp;#8226;';
	$trans['&amp;ndash;']	=	'&amp;#8211;';
	$trans['&amp;mdash;']	=	'&amp;#8212;';
	$trans['&amp;tilde;']	=	'&amp;#732;';
	$trans['&amp;trade;']	=	'&amp;#8482;';
	$trans['&amp;scaron;']	=	'&amp;#353;';
	$trans['&amp;rsaquo;']	=	'&amp;#8250;';
	$trans['&amp;oelig;']	=	'&amp;#339;';
	$trans['&amp;Yuml;']	=	'&amp;#376;';

	$string	=	strtr($string, $trans);
	return $string;
}
</pre>
<p>
Hope it&#8217;s helpful.
</p>
<p>
UPDATE &#8211; apparently, even the numbered entities are not valid XML. Fair enough, I&#8217;ve converted them all to <a href="http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT" target="_blank" rel="nofollow">unicode (0&#215;80 &#8211; 0x9F)</a>. All my ATOM feeds validate now (through <a href="http://feedvalidator.org" target="_blank" rel="nofollow">feedvalidator.org</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/how-tos/how-to-convert-html-named-entities-to-numbered-entities-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

