<?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>BLARGH!! for the people &#187; unicode</title>
	<atom:link href="http://blargh.tommymontgomery.com/category/unicode/feed/" rel="self" type="application/rss+xml" />
	<link>http://blargh.tommymontgomery.com</link>
	<description>It&#039;s time to bring forth the rhythm and the rhyme</description>
	<lastBuildDate>Fri, 09 Jul 2010 04:03:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Transliteration in PHP</title>
		<link>http://blargh.tommymontgomery.com/2009/08/transliteration-in-php/</link>
		<comments>http://blargh.tommymontgomery.com/2009/08/transliteration-in-php/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 19:07:00 +0000</pubDate>
		<dc:creator>tmont</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://blargh.tommymontgomery.com/?p=111</guid>
		<description><![CDATA[This one time, I read this article about how Unicode is for foreigners, and everybody should learn English. It&#8217;s not quite as offensive as it sounds, but it&#8217;s pretty rude. It was awesome.
Anyway, at the end, he called for transliteration implementations in languages besides ones that suck (my words, not his); here of course I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>This one time, I read <a href="http://teddziuba.com/2009/07/this-is-america-take-your-unic.html">this article</a> about how Unicode is for foreigners, and everybody should learn English. It&#8217;s not <em>quite</em> as offensive as it sounds, but it&#8217;s pretty rude. It was awesome.</p>
<p>Anyway, at the end, he called for transliteration implementations in languages besides ones that suck (my words, not his); here of course I&#8217;m referring to Perl, Python and Java. Luckily, PHP is so blindingly awesome that it only requires a function call to do such things. No compiling extensions or importing libraries.</p>
<pre class="brush: php;">
$string = 'Möbius FTW because my name is Rölph Diäålysis';
echo $string . &quot;\n&quot; . iconv('UTF-8', 'ASCII//TRANSLIT', $string);

//The console says this:
/*
M├╢bius FTW because my name is R├╢lph Di├ñ├Ñlysis
M&quot;obius FTW because my name is R&quot;olph Di&quot;aalysis
*/
</pre>
<p>Obviously, it&#8217;s not totally perfect (it tries to approximate the look of them as closely as possible, which is why quotation marks replace the umlauts). This is compiled into PHP by default unless you&#8217;re stupid and decide to disable the <kbd>iconv</kbd> extension for no reason. Don&#8217;t do that. I believe it&#8217;s un-disablable in PHP 5.3.</p>
<p>You can also use the <a href="http://php.net/strtr">strtr</a> function, but then you have to pass the translation characters yourself.</p>
<pre class="brush: php;">
$string = 'Möbius FTW because my name is Rölph Diäålysis';
echo $string . &quot;\n&quot; . strtr($string, array('ö' =&gt; 'o', 'ä' =&gt; 'a', 'å' =&gt; 'a'));

//The console says:
/*
M├╢bius FTW because my name is R├╢lph Di├ñ├Ñlysis
Mobius FTW because my name is Rolph Diaalysis
*/
</pre>
<p>You could fairly easily and non-painlessly write a reusable library function in PHP using <kbd>strtr()</kbd> that will convert from unicode to ASCII, in the spirit of <a href="http://us.php.net/manual/en/function.strtr.php#56973">this</a>.Obviously you wouldn&#8217;t want to write a conversion array for 65000 unicode characters, but you could at least do the characters you use most often.</p>
<p>Another option is the <a href="http://pecl.php.net/package/translit">translit PECL extension</a>. This would require you to compile an extension, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://blargh.tommymontgomery.com/2009/08/transliteration-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
