<?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>Floorplanner Tech Blog &#187; tab character</title>
	<atom:link href="http://techblog.floorplanner.com/tag/tab-character/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Our latest geek adventures!</description>
	<lastBuildDate>Tue, 16 Mar 2010 18:45:44 +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>How to remove hidden tab characters</title>
		<link>http://techblog.floorplanner.com/2008/12/17/how-to-remove-hidden-tab-characters/</link>
		<comments>http://techblog.floorplanner.com/2008/12/17/how-to-remove-hidden-tab-characters/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 13:31:37 +0000</pubDate>
		<dc:creator>Gert-Jan van der Wel</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tab character]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=367</guid>
		<description><![CDATA[At this moment, all the language translations of the Floorplanner 2D app are stored in a database table. Today we discovered that a couple of these translations didn&#8217;t align properly in the interface. After some investigation we discovered that they all contained a hidden tab character at the end of  each string. This was probably [...]]]></description>
			<content:encoded><![CDATA[<p>At this moment, all the language translations of the Floorplanner 2D app are stored in a database table. Today we discovered that a couple of these translations didn&#8217;t align properly in the interface. After some investigation we discovered that they all contained a hidden tab character at the end of  each string. This was probably caused by importing a malformed CSV file.</p>
<p>I thought a simple <strong>REPLACE</strong> query would fix this problem, but (as usual) it was a little more complicated than that. First I had to find the fields with the tab character&#8230; <a href="http://twitter.com/wvanbergen/status/1060635881" target="_blank">Willem</a> pointed me to the right direction with his favorite weapon of choice <strong>REGEXP</strong>. According to the <a href="http://dev.mysql.com/doc/refman/5.1/en/regexp.html" target="_blank">MySQL docs</a> I could find tab characters with something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family: Monaco,monospace;">SELECT <span style="color: #339933;">*</span> FROM table WHERE field REGEXP <span style="color: #0000ff;">'[[.LF.]]'</span></pre></div></div>

<p>The next step was to remove the tab characters. My first thought was to do this by replacing them with an empty string. It turns out you can&#8217;t combine a <strong>REPLACE</strong> with a <strong>REGEXP</strong> in a query. So I used good ol&#8217; PHP for the job. A nice advantage was that I didn&#8217;t have to do any replacing, I could just use the <em>trim()</em> function.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family: Monaco,monospace;"><span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT id, field FROM table WHERE field REGEXP '[[.LF.]]'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$field</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE table SET field = '<span style="color: #006699; font-weight: bold;">$field</span>' WHERE id = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Rather simple, when you know what to do&#8230; Another bug bites the dust!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/12/17/how-to-remove-hidden-tab-characters/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
