<?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>Swedish fika &#187; XHTML</title>
	<atom:link href="http://www.swedishfika.com/category/xhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.swedishfika.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 25 Jul 2010 21:57:57 +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>Escaping from Encoding Hell</title>
		<link>http://www.swedishfika.com/2010/01/19/escaping-from-encoding-hell/</link>
		<comments>http://www.swedishfika.com/2010/01/19/escaping-from-encoding-hell/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 20:33:57 +0000</pubDate>
		<dc:creator>Ida</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://swedishfika.com/?p=792</guid>
		<description><![CDATA[What we gonna talk about here is character encoding and how to convert from ISO-8859-1 to UTF-8. If this doesn&#8217;t seem familiar to you you might want to start learning a bit about it. Cause hell is a scary place and you don&#8217;t want to end up there. This is how to avoid hell and [...]]]></description>
			<content:encoded><![CDATA[<p>What we gonna talk about here is character encoding and how to convert from <a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1">ISO-8859-1</a> to <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a>. If this doesn&#8217;t seem familiar to you you might want to start learning a bit about it. Cause hell is a scary place and you don&#8217;t want to end up there. This is how to avoid hell and for those of you who are struggling in the darkness; this is how to get your ass out of there.<br />
<span id="more-792"></span></p>
<h3>Why would I need to convert?</h3>
<ul>
<li>You are tired of using entities for foreign characters. Hate using things like this &amp;#373; (&#8592; very common character… uhm… ) </li>
<li>You are going to merge your web site with another website. (Which has a different encoding.)</li>
<li>You want to write in more languages. (I&#8217;m talking about languages as in the languages people speak NOT programming languages.) </li>
<li>When generating emails and sending data you have problems with weird signs. </li>
<li>You are mad because ISO-8859-1 doesn&#8217;t contain an euro sign (€). (Isn’t that quite funny? I mean it&#8217;s encoding especially suited for the west of europe.  Yea, yea &amp;euro; I know. But still.) </li>
</ul>
<p>There are more reasons. Feel free to add those in the comments.</p>
<p>The biggest reasons <em>&ldquo;back in the days&rdquo;</em> to use ISO-8859-1 was that it had slightly better support in older user agents. Well those old agents are pretty much gone by now. Who still uses Netscape 4? Hands up! Anyone? Well, that’s what I thought.<br />
All in all UTF-8 is, in the long run, more fit for the future. </p>
<h3>Don’t go to hell</h3>
<p>So what do I mean by &ldquo;Encoding Hell&rdquo;. Well those who has been there know what I mean. It’s when you just switch encoding without properly converting your data and you end up with letters looking sÃ¥ hÃ¤r (that’s the word &ldquo;så här&rdquo; meaning &ldquo;like this&rdquo; in swedish.) I got this nasty letters by opening a file with UTF-8 encoding in my text editor using ISO-8859-1.  And guess what? Opening with the right encoding doesn’t switch the letters back. They are stuck looking nasty. I’m in hell! </p>
<p><img src="http://swedishfika.com/wp-content/uploads/in_hell.jpg" alt="Letters in Encoding Hell" title="In Hell" width="456" height="85" class="alignnone size-full wp-image-802" /></p>
<p>Well this was only one file and sure you can change the letters manually or by using some fancy search/replace-command. But think about if you made this mistake with hundreds or thousands of files? Not nice. Big hell!</p>
<h3>Do it right from the beginning</h3>
<p>The best thing is to avoid Encoding Hell all together. Choose the right encoding from start and you are safe.<br />
But if you must change. First thing. Be careful! If you are careful you will save time. Make up a converting-encoding-plan  first so you know exactly what you are doing. Just don’t start testing. My advice is to always start with a backup. Backup everything you want to convert. If you have a database connected to your webpages don’t forget to back up that one as well.  </p>
<h3>Converting your files</h3>
<p>Don’t even think of converting your files by using your text editor. It usually turns out nasty. There are tools to help us out with this.  You can use the terminal/the command prompt to convert things. Me, myself, I have tried out <a href="http://www.elfdata.com/encodingmaster/">&ldquo;Encoding Master&rdquo;</a>  which I think is simply brilliant. Easy to understand and it converted everything very nicely. It&#8217;s also supported by both PC and Mac.<br />
Don’t forget to add/change the encoding in the headers of the webpages too.<br />
<code>&lt;meta http-equiv="Content-Type" content="text/html;<br />
charset=utf-8"&gt;</code></p>
<h3>Converting your database</h3>
<p>Be careful here. Don’t start adding UTF-8 encoded data into your old database. Make sure it’s converted and pretty first. Otherwise you might end up with a messy mix and bang! You are back in hell!<br />
To change the encoding of your database you must change the encoding of everything. The database itself. Every table in the database and every column that includes some sort of text-value. I’m talking about data of type: char, varchar, tinytext, text, mediumtext and longtext.<br />
Since I lately been working with PHP and MySQL the following will apply to them. If you are working in other languages and other databases you probably need to do some further research to see what is the right methods to use. </p>
<p>To change the databse itself use the following query:<br />
<code>ALTER DATABASE my_database charset=utf8;</code><br />
To change a table use :<br />
<code>ALTER TABLE my_table charset=utf8;</code><br />
To change a column in a table use:<br />
<code>ALTER TABLE my_table MODIFY my_column TEXT CHARACTER SET utf8;</code></p>
<p>Make sure everything in there uses the character set utf8 and <a href="http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html">collation utf8_unicode_ci</a>. Ok? </p>
<h3>Encoding in PHP</h3>
<p>If you are coding in PHP you might have problems with the MySQL and PHP talking UTF-8 language. Solution to this which worked for me was to send the following query:<br />
<code>SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'; </code> This must be done right after connecting to the database. </p>
<p>From <a href="http://simonkjellberg.com">Simon</a> comes this handy tip to those of you who are using MySQLI together with UTF-8:<br />
(With error-handling included as a bonus…)</p>
<p><code>$mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, <br />DB_DATABASE);<br />
if(mysqli_connect_error()){<br />
    throw new Exception('Connection failed<br /> due to the following error: '.$error);<br />
}<br />
   if (!$mysqli->set_charset("utf8")){<br />
   printf("Error loading character set utf8: %s\n", <br />$mysqli->error);<br />
} </code> </p>
<p>It could also be a good idea to add the code below to the beginning of the PHP-files.<br />
<code>mb_language('uni');<br />
mb_internal_encoding('UTF-8');</code></p>
<h3>Last but not Least…</h3>
<p>Always research carefully before changing your encoding. Especially if you are a converting-virgin and are changing the encoding for the first time. Never rely solely on one tutorial. Not even this one which, I need to admit, is not covering everything. This is pretty general info. Hey, you can write a book about encoding and the struggles with converting. So remember to look around. Ask people. Start with a backup. Always. And, again, be careful! </p>
<p>Happy Encoding!</p>
<p>/Ida</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swedishfika.com/2010/01/19/escaping-from-encoding-hell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>W3C Valid HTML &#8800; Good HTML</title>
		<link>http://www.swedishfika.com/2009/04/29/w3c-valid-html-good-html/</link>
		<comments>http://www.swedishfika.com/2009/04/29/w3c-valid-html-good-html/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 09:47:35 +0000</pubDate>
		<dc:creator>Ida</dc:creator>
				<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://swedishfika.com/?p=280</guid>
		<description><![CDATA[Recently I have been thinking a lot about what &#8220;good&#8221; HTML (and/or XHTML) actually is. I have been surprised by noticing that a lot of people seems to be thinking that their HTML is good as long as they&#8217;ve passed the Markup Validation Service at W3C. Sometimes they also add &#8220;and if my site renders [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been thinking a lot about what &#8220;good&#8221; HTML (and/or XHTML) actually is. I have been surprised by noticing that a lot of people seems to be thinking that their HTML is good as long as they&#8217;ve passed <a href="http://validator.w3.org/">the Markup Validation Service at W3C</a>. Sometimes they also add &#8220;and if my site renders well in all browsers&#8221;.<br />
I think that kind of statement is wrong!</p>
<p><span id="more-280"></span></p>
<h3>Why is validation not enough?</h3>
<p>If your website passes the validation check it means that the code you&#8217;ve written is valid. It does NOT mean that:</p>
<ul class="post-list">
<li>- your website is accessible</li>
<li>- your website renders well on all devices and browsers</li>
<li>- your website is optimized</li>
<li>- it doesn&#8217;t even mean that your code is well written (No it doesn&#8217;t!)</li>
</ul>
<p>So let&#8217;s sort this out by asking what HTML actually is.<br />
<a href="http://en.wikipedia.org/wiki/HTML">According to Wikipedia</a> HTML &#8220;provides a means to describe the structure of text-based information in a document&#8221; I think that describes it pretty well.</p>
<p>Let&#8217;s take a look at the following code:</p>
<pre class="brush: html">
&lt;div id=&quot;h-123&quot;&gt;
&lt;span class=&quot;span-b&quot;&gt;
&lt;span class=&quot;big-first-letter&quot;&gt;M&lt;/span&gt;y header
&lt;/span&gt;
&lt;/div&gt;
</pre>
<p>The code above is perfectly valid according to W3C’s Validation Service. But let’s be honest. Do you think this is good descriptive markup? Do you think this markup would be considered semantic? Is it optimized?</p>
<p>Instead consider this code:</p>
<pre class="brush: html">
&lt;h1&gt;My header&lt;/h1&gt;
</pre>
<p>Much shorter and much much better.</p>
<p>So I think you get my point. But if validation isn&#8217;t enough how do you write good HTML? I don&#8217;t know any good application today that can actually give you a good answer to if your HTML is good or not. If you do please feel free to post a comment below.</p>
<h3>A few tips to help you write that &#8220;good&#8221; HTML</h3>
<p>So I’m not gonna give you a perfect easy-to-follow answer. But I’m going to give a few tips which help me when I write HTML.</p>
<ul class="post-list">
<li> &#8211; Think about what you are describing and not what it should look like. A header should not be a h1 just beacuse you want it to look big. In short: HTML is not about appearance!</li>
<li> &#8211; Write (ALL) your structure (i.e. HTML) before trying to achieve whatever design you have in mind. If you do that you will not add the wrong stuff to your code like unecessary classes (known as classitis) and it&#8217;ll also give you a good protection against <a href="http://en.wiktionary.org/wiki/divitis">divitis</a>.</li>
<li>- If you tend to forget about the existence of certain elements have the <a href="http://www.w3schools.com/tags/default.asp">HTML 4.01 / XHTML 1.0 Reference</a> open while writing.</li>
<li>- Use attributes the right way. Like alt and title which people tend to mix up. (Alt is the caption and title is the description.) <a href="http://www.w3.org/TR/html4/index/attributes.html">A list of attributes can be found here.</a></li>
<li>- If you know you have a problem and tend to use to many tags. Try to think less is more. Keep it clean! (And take another look at the header-example above.)</li>
<li>- After adding some style to your website go through <a href="http://www.w3.org/TR/WCAG20/">the guidelines</a>. Yea, I&#8217;ll admit it. I don&#8217;t do this myself that much. But every once in a while try to force yourself to at least skim through the guidelines. And if you like to say that you build truly accessible websites I consider knowing these rules to be a must.</li>
<li>- And as a last step. Validate.</li>
</ul>
<p>Finally remember that if your HTML truly is &#8220;good&#8221; there will be no problem for nobody when it comes to interpret your code. That goes for both screenreaders and search engine spiders.</p>
<p>/Ida</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swedishfika.com/2009/04/29/w3c-valid-html-good-html/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
