<?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>#! &#187; UTF8</title>
	<atom:link href="http://hash-bang.net/tag/utf8/feed/" rel="self" type="application/rss+xml" />
	<link>http://hash-bang.net</link>
	<description>The start of all wonderful things</description>
	<lastBuildDate>Sun, 15 May 2011 03:36:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Talking in tongues &#8211; UTF8 with CodeIgniter</title>
		<link>http://hash-bang.net/2009/02/utf8-with-codeigniter/</link>
		<comments>http://hash-bang.net/2009/02/utf8-with-codeigniter/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 02:55:23 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[UTF8]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=95</guid>
		<description><![CDATA[PHP 4 &#038; 5 unfortunately have major problems working with UTF8. Hopefully this will be solved with PHP6 and its fancy pants new rendering interface. Until then we have to make do and mend. First setup your database to work with UTF8. I won&#8217;t waste time telling you how to do this in MySQL as [...]]]></description>
			<content:encoded><![CDATA[<p>PHP 4 &#038; 5 unfortunately have major problems working with UTF8. Hopefully this <a href="http://www.bionictomato.com/users/Marti-en/154-Preparing-yourself-for-PHP-60.html">will be solved with PHP6</a> and its fancy pants new rendering interface.</p>
<p>Until then we have to make do and mend.</p>
<p>First setup your database to work with UTF8. I won&#8217;t waste time telling you how to do this in MySQL as many people far brighter than I have written <a href="http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html">more on the subject</a>.</p>
<p>CodeIgniter comes with UTF8 enabled out of the box so there is little to do configuration wise. Unfortunately pasting a test string such as: 検索 (which I stole from <a href="http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8">this Wikipedia page</a>) into a CI input box will quickly lead to calamity as CI tries to save the string as ASCII.</p>
<p>Simple solution then, save the following helper in your system/application/helpers folder:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=95&amp;download=utf8_helper.php">utf8_helper.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p953"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p95code3"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
* Rewrite all outgoing text into UTF8 compatible streams
* Author: Matt Carter &lt;m@ttcarter.com&gt;
* Info: http://hash-bang.net/2009/02/utf8-with-codeigniter
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> ob_utf8<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ob_utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Re-write all incoming text into UTF8 streams</span>
	<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Then simply add it to your system/application/autoload.php:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p95code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p954"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p95code4"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'helper'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The helper will automatically convert incoming POST data into MySQL compatible UTF8 and convert outgoing text into HTML UTF8 streams.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/02/utf8-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

