<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Magp.ie &#187; Code</title>
	<atom:link href="http://magp.ie/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://magp.ie</link>
	<description>A nest for the random, shiny, online tidbits I stumble across...</description>
	<lastBuildDate>Wed, 16 May 2012 09:40:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='magp.ie' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/061e340c5da13b5a41ae8016bee03aa8?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Magp.ie &#187; Code</title>
		<link>http://magp.ie</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://magp.ie/osd.xml" title="Magp.ie" />
	<atom:link rel='hub' href='http://magp.ie/?pushpress=hub'/>
		<item>
		<title>HTML5 Data attributes in HTML and jQuery</title>
		<link>http://magp.ie/2011/11/29/html5-data-attributes-in-html-and-jquery/</link>
		<comments>http://magp.ie/2011/11/29/html5-data-attributes-in-html-and-jquery/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 18:18:41 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Guides]]></category>
		<category><![CDATA[data attribute]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json_encode]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=667</guid>
		<description><![CDATA[When writing javascript, it is often necessary to include metadata in the HTML markup, to help define some element or behaviour. There are common options available. You can use hidden inputs and/or standard attributes like class or title to store &#8230; <a href="http://magp.ie/2011/11/29/html5-data-attributes-in-html-and-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=667&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When writing javascript, it is often necessary to include metadata in the HTML markup, to help define some element or behaviour. There are common options available. You can use hidden inputs and/or standard attributes like <code>class</code> or <code>title</code> to store this metadata. However with HTML5&#8242;s data attribute, storing and parsing this data has become a whole lot easier and cleaner.</p>
<p>The syntax is straightforward. Any attribute prefixed with <code>data-</code> will be treated as data storage.</p>
<p><pre class="brush: xml;">&lt;div class=&quot;test&quot; data-foo=&quot;bar&quot;&gt;&lt;/div&gt;</pre></p>
<p>jQuery accesses this data like so&#8230;<br />
<pre class="brush: jscript;">var data = $( 'div.test' ).data( 'foo' ); // returns bar</pre></p>
<p>Support for the data attribute has been added since jQuery <a href="http://blog.jquery.com/2010/10/16/jquery-143-released/" title="version 1.4.3" target="_blank">version 1.4.3</a>. jQuery&#8217;s implementation is smart enough that it can parse the attribute easily and even determine the correct data type used.</p>
<p>What I have found really useful is the fact that the jQuery can parse JSON syntax and return a JSON object. This makes passing data in PHP trivial, using the <a href="http://php.net/manual/en/function.json-encode.php" title="json_encode" target="_blank">json_encode</a> method. We also need to use <a href="http://php.net/manual/en/function.htmlspecialchars.php" title="Escape quotes" target="_blank">htmlspecialchars</a> method to escape or convert any quotes in the JSON string.<br />
<pre class="brush: php;">
&lt;?php  
$test = array( 'row' =&gt; 1, 'col' =&gt; 6, 'color' =&gt; 'pink' ); //create array of data you want to pass to jquery
$test = json_encode( $test ); //convert array to a JSON string
$test = htmlspecialchars( $test, ENT_QUOTES ); //convert any quotes into HTML entities so JSON string behaves as a proper HTML attribute.
?&gt;
&lt;div class=&quot;test&quot; data-complex=&quot;&lt;?php echo $test ; ?&gt;&quot;&gt;&lt;/div&gt;</pre></p>
<p>The jQuery parses the JSON string like so&#8230;<br />
<pre class="brush: jscript;">var test = $( 'div.test' ).data( 'complex' ); // returns JSON Object

console.log( test.color ); // outputs pink!</pre></p>
<p>Important to note that this method is also backward compatible with older browsers, so there is no excuse not to give it a go!</p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a>, <a href='http://magp.ie/category/guides/'>Guides</a> Tagged: <a href='http://magp.ie/tag/data-attribute/'>data attribute</a>, <a href='http://magp.ie/tag/html5/'>html5</a>, <a href='http://magp.ie/tag/jquery/'>jQuery</a>, <a href='http://magp.ie/tag/json/'>json</a>, <a href='http://magp.ie/tag/json_encode/'>json_encode</a>, <a href='http://magp.ie/tag/php/'>php</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/667/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=667&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/11/29/html5-data-attributes-in-html-and-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>Filter IP addresses with PHP</title>
		<link>http://magp.ie/2011/09/01/filter-ip-addresses-with-php/</link>
		<comments>http://magp.ie/2011/09/01/filter-ip-addresses-with-php/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 19:33:47 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[blacklist]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[IP address]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[whitelist]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=642</guid>
		<description><![CDATA[You may at some stage want to filter an online service based on IP address. In other words, you may want to block or grant access to a request based on their IP address. This can be handled in PHP &#8230; <a href="http://magp.ie/2011/09/01/filter-ip-addresses-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=642&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You may at some stage want to filter an online service based on IP address. In other words, you may want to block or grant access to a request based on their IP address. This can be handled in PHP by doing the following.</p>
<p>If you have the IP addresses, then it is trivial.</p>
<p><pre class="brush: php;">

//First check IP address is valid
$request_ip = $_SERVER['REMOTE_ADDR'];

if ( !preg_match( &quot;/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/&quot;, $request_ip ) )
    return false;

$blacklist = array(
'111.222.12.11',
'222.111.21.22',
'221.112.11.12'
);

//check that ip is not blacklisted
if ( in_array( $request_ip, $blacklist ) )
    return false;

</pre></p>
<p>If you want to include a range of IP addresses, best to use a regular expression.</p>
<p><pre class="brush: php;">

$blacklist_ip_range = array(
    '/^122\.244\.(\d+)\.(\d+)/', //for IP address in the range 122.244.0.0 - 122.244.255.255
    '/^123\.(\d+)\.(\d+)\.(\d+)/', //for IP address in the range 123.0.0.0 - 123.255.255.255
);

foreach( $blacklist_ip_range as $ip ) {
    if( preg_match( $ip, $request_ip ) )
       	return false;
    }

</pre></p>
<p>If you have a better solution, then please let me know.</p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/blacklist/'>blacklist</a>, <a href='http://magp.ie/tag/filter/'>filter</a>, <a href='http://magp.ie/tag/ip-address/'>IP address</a>, <a href='http://magp.ie/tag/php/'>php</a>, <a href='http://magp.ie/tag/regular-expression/'>regular expression</a>, <a href='http://magp.ie/tag/whitelist/'>whitelist</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/642/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/642/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/642/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/642/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/642/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/642/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/642/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/642/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/642/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/642/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/642/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/642/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/642/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/642/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=642&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/09/01/filter-ip-addresses-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>Change Float style with Javascript</title>
		<link>http://magp.ie/2011/08/21/change-float-style-with-javascript/</link>
		<comments>http://magp.ie/2011/08/21/change-float-style-with-javascript/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 19:58:54 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=639</guid>
		<description><![CDATA[If you would like to change the float style of some element using javascript, then use the following. Filed under: Code Tagged: dom, javascript, style<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=639&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you would like to change the float style of some element using javascript, then use the following.</p>
<p><pre class="brush: jscript;">

var element = document.getElementById( 'some_element_id' );

element.style.cssFloat = 'left';

</pre></p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/dom/'>dom</a>, <a href='http://magp.ie/tag/javascript/'>javascript</a>, <a href='http://magp.ie/tag/style/'>style</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/639/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=639&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/08/21/change-float-style-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>How to check if an element exists in jQuery</title>
		<link>http://magp.ie/2011/08/03/how-to-check-if-an-element-exists-in-jquery/</link>
		<comments>http://magp.ie/2011/08/03/how-to-check-if-an-element-exists-in-jquery/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 20:02:56 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[exists]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[selector]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=606</guid>
		<description><![CDATA[Briefer again&#8230; via http://aaronrussell.co.uk/legacy/check-if-an-element-exists-using-jquery/ Filed under: Code Tagged: exists, jQuery, selector<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=606&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: jscript;">
if ( $(&quot;#mydiv&quot;).length ){
  // do something here
}
</pre></p>
<p>Briefer again&#8230;</p>
<p><pre class="brush: jscript;">
if ( $(&quot;#mydiv&quot;)[0] ){
  // do something here
}
</pre></p>
<p>via <a title="check-if-an-element-exists-using-jquery" href="http://aaronrussell.co.uk/legacy/check-if-an-element-exists-using-jquery/" target="_blank">http://aaronrussell.co.uk/legacy/check-if-an-element-exists-using-jquery/</a></p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/exists/'>exists</a>, <a href='http://magp.ie/tag/jquery/'>jQuery</a>, <a href='http://magp.ie/tag/selector/'>selector</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/606/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/606/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/606/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/606/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/606/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/606/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/606/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/606/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/606/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/606/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/606/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/606/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/606/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/606/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=606&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/08/03/how-to-check-if-an-element-exists-in-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>Faster Javascript Trim</title>
		<link>http://magp.ie/2011/07/28/faster-javascript-trim/</link>
		<comments>http://magp.ie/2011/07/28/faster-javascript-trim/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 21:25:02 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[trim]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=592</guid>
		<description><![CDATA[Want the best way to trim a sting in javascript? A while ago, I came across a post on such a subject. It was written a few years ago but it&#8217;s still as relevant and useful as ever. http://blog.stevenlevithan.com/archives/faster-trim-javascript  The &#8230; <a href="http://magp.ie/2011/07/28/faster-javascript-trim/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=592&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Want the best way to trim a sting in javascript?</p>
<p>A while ago, I came across a post on such a subject. It was written a few years ago but it&#8217;s still as relevant and useful as ever.</p>
<p><span id="more-592"></span></p>
<p><a title="faster-trim-javascript " href="http://blog.stevenlevithan.com/archives/faster-trim-javascript" target="_blank">http://blog.stevenlevithan.com/archives/faster-trim-javascript </a></p>
<p>The author basically compares a bunch of different methods to trim a string across the 2 big browsers at the time, Internet Explorer and Firefox, and figures out the fastest way of doing it.</p>
<p>For more detail, follow the link above, otherwise, here is the conclusion.</p>
<p><strong>Fastest trim method for normal length strings</strong></p>
<p><pre class="brush: jscript;">
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
</pre></p>
<p><strong>Fastest trim method for super long strings</strong></p>
<p><pre class="brush: jscript;">
function trim11 (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i &gt;= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
</pre></p>
<p><strong>Note</strong>: For the super geeks out there, <a title="Trim testing" href="http://jsperf.com/mega-trim-test" target="_blank">this site will show you and allow you to test what is the fastest trim method on a particular browser&#8230; enjoy</a>!</p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/fast/'>fast</a>, <a href='http://magp.ie/tag/javascript/'>javascript</a>, <a href='http://magp.ie/tag/optimize/'>optimize</a>, <a href='http://magp.ie/tag/regex/'>regex</a>, <a href='http://magp.ie/tag/trim/'>trim</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/592/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/592/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/592/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=592&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/07/28/faster-javascript-trim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>Tidy assignments in Coda and TextWrangler</title>
		<link>http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/</link>
		<comments>http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 08:40:28 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[assignments]]></category>
		<category><![CDATA[coda]]></category>
		<category><![CDATA[indentation]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[textwrangler]]></category>
		<category><![CDATA[tidy code]]></category>
		<category><![CDATA[Unix filter]]></category>
		<category><![CDATA[WordPress coding standards]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=529</guid>
		<description><![CDATA[I have written a simple tool to tidy assignments. It basically takes a group of assignments and uses spaces to make the code more readable. This tool will help code meet the indentation rules in the WordPress coding standards. If &#8230; <a href="http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=529&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have written a simple tool to tidy assignments. It basically takes a group of assignments and uses spaces to make the code more readable.</p>
<p>This tool will help code meet the indentation rules in the <a href="http://codex.wordpress.org/WordPress_Coding_Standards#Indentation"> WordPress coding standards</a>.<br />
<span id="more-529"></span><br />
If you have a group of basic assignments like&#8230;</p>
<p><pre class="brush: php;">
$variable1 = 0;
$long_variable2 = 123213123;
$short = 'test';
$s = 'test2';
</pre></p>
<p>This tool will space them so&#8230;</p>
<p><pre class="brush: php;">
$variable1      = 0;
$long_variable2 = 123213123;
$short          = 'test';
$s              = 'test2';
</pre></p>
<p>It will also work associative arrays&#8230;</p>
<p><pre class="brush: php;">
array(
'magpie' =&gt; 0,
'blog' =&gt; 1,
'random' =&gt; 2,
'too_long_string' =&gt; 3
);
</pre></p>
<p>&#8230; with spacing &#8230;</p>
<p><pre class="brush: php;">
array(
'magpie'          =&gt; 0,
'blog'            =&gt; 1,
'random'          =&gt; 2,
'too_long_string' =&gt; 3
);
</pre></p>
<p>The tool is available as a Coda plugin and a TextWrangler UNIX filter.</p>
<h4>For Coda</h4>
<ul>
<li><a href="http://dl.dropbox.com/u/5756988/tidy-assignment.codaplugin.zip">Download the Coda plugin</a></li>
<li>Extract the zip file and double-click the <strong>tidy-assignment.codaplugin</strong> file</li>
<li>Select code, right-click, goto Plug-ins-&gt;Tidy Assignment</li>
</ul>
<p><img src="http://blogalhost.files.wordpress.com/2011/03/highlight.png?w=450&h=261" alt="Highlight and select Tidy Assignment plugin" title="highlight-code" width="450" height="261" class="alignnone size-full wp-image-542" /></p>
<p>To remove/uninstall the plugin;</p>
<ul>
<li>Close Coda</li>
<li>Goto <code>[your_home_folder]/Library/Application Support/Coda/Plug-ins/</code></li>
<li>Delete the file tidy-assignment.codaplugin</li>
</ul>
<h4>For TextWrangler</h4>
<ul>
<li>Open TextWrangler and open a new text file.</li>
<li>Copy and paste the code below into this file.</li>
<p><pre class="brush: php;">
#!/usr/bin/php
&lt;?php

if ( !isset( $_SERVER['argv'] ) &amp;&amp; !isset( $_SERVER['argv'][1] ) )
	die();

$fc    = file_get_contents( $_SERVER['argv'][1] );
$lines = explode( &quot;\n&quot;, $fc );
$clean = array();
$assoc = false;

$longest_line_index  = 0;
$longest_line_length = 0;

foreach ( $lines as $key =&gt; $line ) {
	//remove whitspace
	$line = preg_replace( '/\s\s+/', ' ', trim( $line ) );
	$parts = array();
	
	if ( mb_stripos( $line, '=&gt;' ) !== FALSE ) {
		$parts = explode( &quot;=&gt;&quot;, $line );
		$assoc = true;
	}
	elseif ( mb_stripos( $line, '=' ) !== FALSE ) {
		$parts = explode( &quot;=&quot;, $line );
	}

	if ( !empty( $parts ) &amp;&amp; mb_strlen( $parts[0] ) &gt; $longest_line_length ) {
		$longest_line_index = $key;
		$longest_line_length = mb_strlen( $parts[0] );
	}
	
	if ( mb_strlen( $line ) &gt; 0 )
		$clean[$key] = $line;
}

$longest_line = $clean[$longest_line_index];
$operator = $assoc ? '=&gt;' : '=' ;

//add spaces to line
if ( mb_stripos( $longest_line, $operator ) !== FALSE ) {
	$parts = explode( $operator, $longest_line );
	$longest_line = sprintf( &quot;%s %s %s&quot;, trim( $parts[0] ), $operator, trim( $parts[1] ) );
}
else {
	$longest_line = sprintf( &quot;%s&quot;, trim( $longest_line ) );
}

//now get the position of equals
$pos = mb_stripos( $longest_line, $operator );
if ( $pos === FALSE )
	$pos = mb_strlen( $longest_line );

foreach ( $clean as $key =&gt; &amp;$line ) {
	if ( $key == $longest_line_index )
		$line = $longest_line;
	elseif ( mb_stripos( $line, $operator ) !== FALSE ) {
		$spaces = ' ';
		$parts = explode( $operator, $line );
		if ( !empty( $parts ) )
			while ( mb_stripos( $line, $operator ) &lt; $pos ) {
				$line = sprintf( &quot;%s%s%s %s&quot;, trim( $parts[0] ), $spaces, $operator, trim( $parts[1] ) );
				$spaces .= &quot; &quot;;
			}
	}
	else {
		$line = sprintf( &quot;%s&quot;, trim( $line ) );
	}
}

echo implode( &quot;\n&quot;, $clean );
</pre></p>
<li>Save the file, something like <strong>Tidy Assignment.php</strong>, in the Filters folder.</li>
<li>You can find the filters folder by going to the <em>#! menu</em> and go to the <em>Unix Filters</em> sub-menu, and select the <em>Open Filters Folder</em>, like below.<br />
<img class="alignnone size-full wp-image-98" title="Scripts menu" src="http://blogalhost.files.wordpress.com/2010/02/picture-7.png?w=450" alt=""   /></p>
<li>Now anytime you want to tidy assignments, just go to this menu and select the <strong>Tidy Assignment</strong> script.</li>
<p><img src="http://blogalhost.files.wordpress.com/2011/03/tidy-assignment-textwrangler.png?w=450&h=373" alt="Select tidy assignment script in TextWrangler" title="tidy-assignment-textwrangler" width="450" height="373" class="alignnone size-full wp-image-544" />
</ul>
<p>First time I <a href="http://www.panic.com/coda/developer/">created a coda plugin</a> and I am surprised how simple it is. I may experiment with this in the future if I can think of anything useful.</p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/assignments/'>assignments</a>, <a href='http://magp.ie/tag/coda/'>coda</a>, <a href='http://magp.ie/tag/indentation/'>indentation</a>, <a href='http://magp.ie/tag/plugin/'>plugin</a>, <a href='http://magp.ie/tag/textwrangler/'>textwrangler</a>, <a href='http://magp.ie/tag/tidy-code/'>tidy code</a>, <a href='http://magp.ie/tag/unix-filter/'>Unix filter</a>, <a href='http://magp.ie/tag/wordpress-coding-standards/'>WordPress coding standards</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/529/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=529&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<georss:point>53.734700 -8.991280</georss:point>
		<geo:lat>53.734700</geo:lat>
		<geo:long>-8.991280</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2011/03/highlight.png" medium="image">
			<media:title type="html">highlight-code</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/02/picture-7.png" medium="image">
			<media:title type="html">Scripts menu</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2011/03/tidy-assignment-textwrangler.png" medium="image">
			<media:title type="html">tidy-assignment-textwrangler</media:title>
		</media:content>
	</item>
		<item>
		<title>Check for Valid XML with PHP</title>
		<link>http://magp.ie/2011/02/12/check-for-valid-xml-with-php/</link>
		<comments>http://magp.ie/2011/02/12/check-for-valid-xml-with-php/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 18:23:11 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[DOMDocument]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[validate]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=513</guid>
		<description><![CDATA[Simple function to check if XML is valid. It just loads the XML into DOMDocument and checks for errors. Filed under: Code Tagged: DOMDocument, php, validate, XML<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=513&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Simple function to check if XML is valid. It just loads the XML into <a href="http://php.net/manual/en/class.domdocument.php">DOMDocument</a> and checks for errors.</p>
<p><pre class="brush: php;">
/**
*  Takes XML string and returns a boolean result where valid XML returns true
*/
function is_valid_xml ( $xml ) {
    libxml_use_internal_errors( true );
    
    $doc = new DOMDocument('1.0', 'utf-8');
    
    $doc-&gt;loadXML( $xml );
    
    $errors = libxml_get_errors();
    
    return empty( $errors );
}
</pre></p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/domdocument/'>DOMDocument</a>, <a href='http://magp.ie/tag/php/'>php</a>, <a href='http://magp.ie/tag/validate/'>validate</a>, <a href='http://magp.ie/tag/xml/'>XML</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/513/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=513&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/02/12/check-for-valid-xml-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>Find duplicates in an array with PHP</title>
		<link>http://magp.ie/2011/02/02/find-duplicates-in-an-array-with-php/</link>
		<comments>http://magp.ie/2011/02/02/find-duplicates-in-an-array-with-php/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 18:07:25 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[duplicates]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=507</guid>
		<description><![CDATA[Here is a function to find duplicate items in an array. Filed under: Code Tagged: array, duplicates, php<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=507&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a function to find duplicate items in an array.</p>
<p><pre class="brush: php;">
/**
* Takes an array and returns an array of duplicate items
*/
function get_duplicates( $array ) {
	return array_unique( array_diff_assoc( $array, array_unique( $array ) ) );
}
</pre></p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/array/'>array</a>, <a href='http://magp.ie/tag/duplicates/'>duplicates</a>, <a href='http://magp.ie/tag/php/'>php</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/507/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=507&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/02/02/find-duplicates-in-an-array-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>Regular expression to remove excess whitespace</title>
		<link>http://magp.ie/2011/01/30/regular-expression-to-remove-excess-whitespace/</link>
		<comments>http://magp.ie/2011/01/30/regular-expression-to-remove-excess-whitespace/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 15:11:38 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[tabs]]></category>
		<category><![CDATA[whitespace]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=503</guid>
		<description><![CDATA[Neat way of removing excess whitespace and tabbing from strings. Filed under: Code Tagged: php, regex, strings, tabs, whitespace<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=503&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Neat way of removing excess whitespace and tabbing from strings.</p>
<p><pre class="brush: php;">
$string = &quot;Tom\tThumb\t                is sooooooo\t\t\tdumb&quot;;
$string = preg_replace( '/\s+/', ' ', $string );
echo $string;
//will echo &quot;Tom Thumb is sooooooo dumb&quot;
</pre></p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/php/'>php</a>, <a href='http://magp.ie/tag/regex/'>regex</a>, <a href='http://magp.ie/tag/strings/'>strings</a>, <a href='http://magp.ie/tag/tabs/'>tabs</a>, <a href='http://magp.ie/tag/whitespace/'>whitespace</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/503/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=503&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/01/30/regular-expression-to-remove-excess-whitespace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>Convert CSV data into an associative array</title>
		<link>http://magp.ie/2011/01/28/convert-csv-data-into-an-associative-array/</link>
		<comments>http://magp.ie/2011/01/28/convert-csv-data-into-an-associative-array/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 14:41:29 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=496</guid>
		<description><![CDATA[If you want to convert comma separated values into an associated array, then use the following code. Note: The code uses the first row of your CSV data to determine the keys in the associative array. Found here, courtesy of &#8230; <a href="http://magp.ie/2011/01/28/convert-csv-data-into-an-associative-array/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=496&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you want to convert comma separated values into an associated array, then use the following code.<br />
<span id="more-496"></span><br />
<strong>Note:</strong> The code uses the first row of your CSV data to determine the keys in the associative array.</p>
<p><pre class="brush: php;">
/**
 * Convert a comma separated file into an associated array.
 * The first row should contain the array keys.
 * 
 * Example:
 * 
 * @param string $filename Path to the CSV file
 * @param string $delimiter The separator used in the file
 * @return array
 * @link http://gist.github.com/385876
 * @author Jay Williams &lt;http://myd3.com/&gt;
 * @copyright Copyright (c) 2010, Jay Williams
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
function csv_to_array($filename='', $delimiter=',')
{
	if(!file_exists($filename) || !is_readable($filename))
		return FALSE;

	$header = NULL;
	$data = array();
	if (($handle = fopen($filename, 'r')) !== FALSE)
	{
		while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
		{
			if(!$header)
				$header = $row;
			else
				$data[] = array_combine($header, $row);
		}
		fclose($handle);
	}
	return $data;
}
</pre></p>
<p><a href="https://gist.github.com/385876">Found here</a>, courtesy of <a href="https://gist.github.com/jaywilliams">jaywilliams</a></p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/array/'>array</a>, <a href='http://magp.ie/tag/csv/'>CSV</a>, <a href='http://magp.ie/tag/format/'>format</a>, <a href='http://magp.ie/tag/github/'>github</a>, <a href='http://magp.ie/tag/parse/'>parse</a>, <a href='http://magp.ie/tag/php/'>php</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/496/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=496&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/01/28/convert-csv-data-into-an-associative-array/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
	</channel>
</rss>
