<?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>Xavi Esteve &#187; Apache</title>
	<atom:link href="http://xaviesteve.com/category/web-design/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://xaviesteve.com</link>
	<description>I&#039;m a front end web developer and graphic designer from Barcelona based in London. I am passionate in JavaScript, jQuery, CSS, PHP, Wordpress, usability and SEO.</description>
	<lastBuildDate>Wed, 08 Feb 2012 16:22:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Issues with accents and strange characters in PHP/MySQL (Solved)</title>
		<link>http://xaviesteve.com/1223/issues-with-accents-and-strange-characters-in-php-mysql-solved/</link>
		<comments>http://xaviesteve.com/1223/issues-with-accents-and-strange-characters-in-php-mysql-solved/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 14:11:43 +0000</pubDate>
		<dc:creator>Xavi</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[accents]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://xaviesteve.com/issues-with-accents-and-strange-characters-in-phpmysql-solved/</guid>
		<description><![CDATA[Usually, when creating a website in PHP and MySQL, there&#8217;s a problem when introducing accents and strange characters, typically from foreign languages like Spanish or French: these get changed into Ã¡Ã³Ã± and similar strange stuff. This happened to me a while ago and I freaked out and started tweaking everything, changing charsets and converting everything [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-large wp-image-860" title="error-con-acentos-y-enes" src="http://xaviesteve.com/wp-content/uploads/2009/05/error-con-acentos-y-enes-600x399.jpg" alt="" width="600" height="399" /></p>
<p>Usually, when creating a website in <strong>PHP and MySQL</strong>, there&#8217;s a problem when introducing accents and strange characters, typically from foreign languages like Spanish or French: these get changed into <strong>Ã¡Ã³Ã±</strong> and similar strange stuff.<br />
This happened to me a while ago and I freaked out and started tweaking everything, changing charsets and converting everything to HTML safe like <strong>&amp;oacute;</strong> but none of these worked or I had such a big database already that it would take ages to change everything manually.</p>
<p>The problem here is that the charset of special characters is not the same in the MySQL database, the PHP language compiler and the Apache server.</p>
<p>So I started to investigate and after some research I&#8217;ve made up a step-by-step list of all the essential things you should check and do in order to solve this. 98% of the people that have tried this have been successful.</p>
<h2>Step by Step Guide on How to Solve the Encoding Issues with Weird Characters</h2>
<ol>
<li>When creating the database in MySQL make sure all the <strong>string fields</strong> have <strong><code>utf8_spanish_ci</code></strong> charset and the <strong>charset</strong> of the tables is<br />
<strong><code>utf_unicode_ci</code></strong> <em>(you can change it later in phpMyAdmin going to Operations &gt; Collation)</em></li>
<li>Make sure you specify a Content-type in all your HTML files, inside the <strong><code>&lt;head&gt;</code></strong> tag:
<pre><strong>&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;</strong></pre>
</li>
<li>And in those files you output without HTML headers (XML, AJAX/JSON calls, APIs&#8230;) put this in the PHP:
<pre><strong>header("Content-Type: text/html;charset=utf-8");</strong></pre>
</li>
<li>When establishing the connection between PHP and MySQL send this query before any other:
<pre><strong>mysql_query("SET NAMES 'utf8'");</strong></pre>
</li>
<li>Remove the <strong><code>DefaultCharset</code></strong> in Apache or modify it</li>
</ol>
<hr />Following these steps will solve the weird accents problem in your server. If it still doesn&#8217;t work post a comment below and we&#8217;ll help you.</p>
<p><small>Photo by <a href="http://www.flickr.com/photos/eduardox/">Eduardo</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://xaviesteve.com/1223/issues-with-accents-and-strange-characters-in-php-mysql-solved/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Error con acentos y eÑes en PHP/MySQL (Solucionado)</title>
		<link>http://xaviesteve.com/354/acentos-y-enes-aparecen-mal-a%c2%b1-en-php-con-mysql-utf-8-iso-8859-1/</link>
		<comments>http://xaviesteve.com/354/acentos-y-enes-aparecen-mal-a%c2%b1-en-php-con-mysql-utf-8-iso-8859-1/#comments</comments>
		<pubDate>Sat, 23 May 2009 02:19:43 +0000</pubDate>
		<dc:creator>Xavi</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Español]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[acentos]]></category>
		<category><![CDATA[cotejamiento]]></category>
		<category><![CDATA[eñes]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[funciona]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[iso-8859-1]]></category>
		<category><![CDATA[problema]]></category>
		<category><![CDATA[quitar]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://xaviesteve.com/?p=354</guid>
		<description><![CDATA[Muchas veces al crear una web con PHP y MySQL, ocurre un problema al introducir y mostrar datos: estos se alteran acabando en Ã¡Ã³Ã± y cosas parecidas. Cuando me pasa esto suelo empezar a toquetear cosas, cambiar charsets y traducir a &#38;ntilde; o &#38;aacute; pero nada funciona. El problema es que la configuración del cotejamiento [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-large wp-image-860" title="error-con-acentos-y-enes" src="http://xaviesteve.com/wp-content/uploads/2009/05/error-con-acentos-y-enes-600x399.jpg" alt="" width="600" height="399" /></p>
<p>Muchas veces al crear una web con <strong>PHP y MySQL</strong>, ocurre un problema al introducir y mostrar datos: estos se alteran acabando en <strong>Ã¡Ã³Ã±</strong> y cosas parecidas. Cuando me pasa esto suelo empezar a toquetear cosas, cambiar charsets y traducir a <em>&amp;ntilde;</em> o <em>&amp;aacute;</em> pero nada funciona. El problema es que la configuración del cotejamiento de los caracteres especiales como acentos, eñes y demás símbolos no es el mismo entre la base de datos (MySQL), el lenguaje de servidor (PHP) y el servidor (Apache).</p>
<p>Así que me puse a buscar y después de encontrar comentarios buenísimos de gente por los foros puedo hacer un resumen de todo lo necesario cuando nos ocurre un problema de estos (id haciendo y testeando si ya funciona todo bien paso a paso).</p>
<h2>Guía paso a paso para solucionar el problema de los acentos y eñes</h2>
<ol>
<li>Al crear la base de datos MySQL, asegúrate que los <strong>campos string</strong> y demás esten en <strong><code>utf8_spanish_ci</code></strong> y el<strong> cotejamiento de las tablas</strong> en<br />
<strong><code>utf_unicode_ci</code></strong> <em>(más tarde en Operations &gt; </em><em>Collation de phpMyAdmin se puede cambiar)</em></li>
<li>Pon en el <strong><code>&lt;head&gt;</code></strong>de todos los archivos HTML:
<pre><strong>&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;</strong></pre>
</li>
<li>Y en los puramente PHP (que muestran XML, llamadas de AJAX, APIs&#8230;) pon el código:
<pre><strong>header("Content-Type: text/html;charset=utf-8");</strong></pre>
</li>
<li>Al crear la conexión de PHP con MySQL, envía esta consulta justo tras la conexión:
<pre><strong>mysql_query("SET NAMES 'utf8'");</strong></pre>
<pre><em>(Para MySQLi escribe </em>$acentos = $db-&gt;query("SET NAMES 'utf8'");<em> gracias <a href="#comment-1189">Fernando</a>)</em></pre>
</li>
<li>Quita el <strong><code>DefaultCharset</code></strong> del Apache o modifícalo</li>
<li>Como última y desesperada opción, quita todos los <strong><code>htmlentities();</code> y sustitúyelo por otro parser para &#8216;sanitizar&#8217; los datos.</strong></li>
</ol>
<p>Haciendo estos pasos se solucionará cualquier problema de codificación de caracteres.</p>
<p>Si te ha servido este artículo ahorra la frustración a otros programadores compartiendo el artículo, <strong><a title="Tweet" href="http://twitter.com/share?url=http%3A%2F%2Fxaviesteve.com%2Facentos-y-enes-aparecen-mal-a%25c2%25b1-en-php-con-mysql-utf-8-iso-8859-1%2F&amp;text=Error%20con%20acentos%20y%20e%C3%91es%20en%20PHP/MySQL%20(Solucionado)%20@xaviesteve">Tweetea en Twitter</a></strong> o <strong><a href="http://www.facebook.com/sharer.php?u=http://xaviesteve.com/acentos-y-enes-aparecen-mal-a%c2%b1-en-php-con-mysql-utf-8-iso-8859-1/&amp;t=Error%20con%20acentos%20y%20e%C3%91es%20en%20PHP/MySQL%20(Solucionado)">Comparte en Facebook</a></strong>.</p>
<p>Como último consejo, si estás aprendiendo PHP y MYSQL te recomiendo que te leas el libro <strong><a href="http://www.amazon.es/gp/product/8441523894/ref=as_li_ss_tl?ie=UTF8&amp;tag=xavest03-21&amp;linkCode=as2&amp;camp=3626&amp;creative=24822&amp;creativeASIN=8441523894" rel="nofollow">PHP y MySQL de O&#8217;Reilly</a></strong> (enlace a la edición de tapa blanda que es más barata) ya que es muy completo y te ayudará a entender todos los problemas de charsets y demás obstáculos a los que te enfrentarás en el futuro.</p>
<p><small>Fotografía por <a href="http://www.flickr.com/photos/eduardox/">Eduardo</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://xaviesteve.com/354/acentos-y-enes-aparecen-mal-a%c2%b1-en-php-con-mysql-utf-8-iso-8859-1/feed/</wfw:commentRss>
		<slash:comments>177</slash:comments>
		</item>
	</channel>
</rss>

