<?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>strictlyPHP &#187; unicode</title>
	<atom:link href="http://www.strictlyphp.com/blog/tag/unicode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.strictlyphp.com/blog</link>
	<description>web development &#38; web analytics</description>
	<lastBuildDate>Sun, 01 Aug 2010 12:00:16 +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>UTF-8 encoded data in PHP and MySQL</title>
		<link>http://www.strictlyphp.com/blog/2009/01/20/utf-8-encoded-data-in-php-and-mysql/</link>
		<comments>http://www.strictlyphp.com/blog/2009/01/20/utf-8-encoded-data-in-php-and-mysql/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 21:09:54 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://www.strictlyphp.com/blog/?p=676</guid>
		<description><![CDATA[
Since every developer has probably struggled with data encoding once in their career, a short summary &#8220;how to get your data in and out of a MySQL database with PHP&#8221;:

When you create your MySQL database, set the collation to one of the UTF-8 options (e.g.: utf8_general_ci). If you have no rights to create or change [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-683" style="float: right;margin: 0 0 10px 10px;" title="unicode" src="http://www.strictlyphp.com/blog/wp-content/uploads/2009/01/unicode.png" alt="unicode" width="100" height="139" /></p>
<p><em>Since every developer has probably struggled with data encoding once in their career, a short summary &#8220;how to get your data in and out of a MySQL database with PHP&#8221;:</em></p>
<ul>
<li>When you create your MySQL database, <strong>set the collation to one of the UTF-8 options</strong> (e.g.: <span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">utf8_general_ci). If you have no rights to create or change your database, do this on the table level.<br />
<em>Note:</em> if you use phpMyAdmin, it&#8217;s good to set your &#8220;session&#8221; encoding to UTF-8 before you sign in (although I believe this is now the default). Otherwise perfectly good data could look weird.<br />
</span></span></span></li>
<li><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">Secondly, when you create a database connection in PHP, be sure to <strong>set the character set of your connection to UTF-8</strong> by executing<br />
</span></span></span></p>
<pre><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">SET NAMES 'utf8'</span></span></span></pre>
<p><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">(notice the missing dash). Some extensions/adapters may have a method to do this</span></span></span><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable"> (e.g. PDO)</span></span></span><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable"> or allow you to pass it as an option.</span></span></span></li>
<li><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">Third, <strong>save your PHP script/file as UTF-8 no-<a href="http://en.wikipedia.org/wiki/Byte-order_mark" target="_blank">BOM</a></strong> (no byte-order mark since UTF-8 does not have byte order issues).</span></span></span></li>
<li><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">Last, but most important &amp; applicable to many more projects: <strong>set the charset of your page through the HTTP header</strong>. e.g.:<br />
</span></span></span></p>
<pre><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">header('Content-Type: text/html;charset=utf-8');</span></span></span></pre>
<p><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable"> <em>Note</em>: do not use the &lt;meta&gt; tag (solely) for this.  Only using the meta tag causes most browsers to start re-parsing your content once they notice it&#8217;s UTF-8 instead of their default assumption. This only slows down page loading.</span></span></span></li>
</ul>
<p>This post is certainly not meant to be a Unicode manual but it can be a quick reference when you every wonder why you see those strange characters in your database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.strictlyphp.com/blog/2009/01/20/utf-8-encoded-data-in-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
