<?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>My Quick Fix &#187; PHP</title>
	<atom:link href="http://myquickfix.co.uk/index.php/category/computers/web-development/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://myquickfix.co.uk</link>
	<description>Quick fixes for niggly problems...</description>
	<lastBuildDate>Thu, 24 Sep 2009 15:10:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Swap days and months in PHP &#8211; quick and dirty MM/DD/YY to DD/MM/YY.</title>
		<link>http://myquickfix.co.uk/index.php/2009/09/swap-days-and-months-in-php-quick-and-dirty-mmddyy-to-ddmmyy/</link>
		<comments>http://myquickfix.co.uk/index.php/2009/09/swap-days-and-months-in-php-quick-and-dirty-mmddyy-to-ddmmyy/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 15:10:50 +0000</pubDate>
		<dc:creator>hutch</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.myquickfix.co.uk/?p=580</guid>
		<description><![CDATA[Problem
I have a ton of date strings in the stupid US style dd/mm/yy format. i.e. 12/24/09 being 24th September 2009. I need to convert them to the UK style dd/mm/yy.
Solution 1
As a string in PHP is really just an array of characters, the simplest fix was to address the individual number characters by their positions within the sting, and rearrange them into the format I wanted:

$d = "12/24/09";
$d = $d[3].$d[4]."/".$d[0].$d[1]."/".$d[6].$d[7];
echo $d; // displays "24/12/19".

Solution 2
I posted my solution on twitter (@hutchings) and asked for comments and @londonhackspace organiser Jonty came ...]]></description>
			<content:encoded><![CDATA[<h2>Problem</h2>
<p>I have a ton of date strings in the stupid US style dd/mm/yy format. i.e. 12/24/09 being 24th September 2009. I need to convert them to the UK style dd/mm/yy.</p>
<h2>Solution 1</h2>
<p>As a string in PHP is really just an array of characters, the simplest fix was to address the individual number characters by their positions within the sting, and rearrange them into the format I wanted:</p>
<pre name="code" class="php">
$d = "12/24/09";
$d = $d[3].$d[4]."/".$d[0].$d[1]."/".$d[6].$d[7];
echo $d; // displays "24/12/19".
</pre>
<h2>Solution 2</h2>
<p>I posted my solution on twitter (@hutchings) and asked for comments and @londonhackspace organiser Jonty came back with the following elegant (and much cleverer) suggestion:</p>
<pre name="code" class="php">
$d = "12/24/09";
$d = preg_replace('|(\d+)/(\d+)/(\d+)|', '$2/$1/$3', $d);
echo $d; // displays "24/12/19".
</pre>
<p>So provided you know that your original string is in US format, both these solutions can be used. In my testing I found solution 1 executed more quickly, but isn&#8217;t as pleasing to look at <img src='http://myquickfix.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Cheers Jonty.</p>
]]></content:encoded>
			<wfw:commentRss>http://myquickfix.co.uk/index.php/2009/09/swap-days-and-months-in-php-quick-and-dirty-mmddyy-to-ddmmyy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Permanent redirect (HTTP 301) to specific domain while preserving querystring.</title>
		<link>http://myquickfix.co.uk/index.php/2008/12/permanent-redirect-http-301-to-specific-domain-while-preserving-querystring/</link>
		<comments>http://myquickfix.co.uk/index.php/2008/12/permanent-redirect-http-301-to-specific-domain-while-preserving-querystring/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 18:24:45 +0000</pubDate>
		<dc:creator>hutch</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.myquickfix.co.uk/?p=7</guid>
		<description><![CDATA[Problem
When you&#8217;re using several domains which all point to one website, it&#8217;s important to make sure that Google only sees on domain when it&#8217;s crawling your site for content. Otherwise you&#8217;ll likely end up with &#8216;suplemental result&#8217; listings in the SERPS. At worst they&#8217;ll dump the site thinking it&#8217;s duplicating content.
A Solution
So what you need is something to intelligently redirect traffic to your preferred domain, while preserving any path and querystring data also. To do this with PHP you can place the following code (in an include maybe?) into the ...]]></description>
			<content:encoded><![CDATA[<h2>Problem</h2>
<p>When you&#8217;re using several domains which all point to one website, it&#8217;s important to make sure that Google only sees on domain when it&#8217;s crawling your site for content. Otherwise you&#8217;ll likely end up with &#8216;suplemental result&#8217; listings in the SERPS. At worst they&#8217;ll dump the site thinking it&#8217;s duplicating content.</p>
<h2>A Solution</h2>
<p>So what you need is something to intelligently redirect traffic to your preferred domain, while preserving any path and querystring data also. To do this with PHP you can place the following code (in an include maybe?) into the head of each page on the site:</p>
<blockquote><p><span style="color: #ff0000;">&lt;?php</span><br />
<span style="color: #0000ff;">$primary = &#8220;www.whatever.com&#8221;;<br />
if ($_SERVER['HTTP_HOST']!= $primary) {<br />
  header(&#8220;HTTP/1.1 301 Moved Permanently&#8221;);<br />
  header(&#8220;Location: http://$primary&#8221;<br />
  .(($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : &#8220;?&#8221;<br />
  .$_SERVER['QUERY_STRING']));<br />
  exit;;<br />
}</span><br />
<span style="color: #ff0000;">?&gt;</span></p></blockquote>
<p>This should redirect the page to the new domain, but preserve the <a title="URI Syntax reference" href="http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax">path, query and any fragaments</a>. Please be aware that not all servers send the complete set of $_SERVER Variables. Using the code above, if the HTTP_HOST variable isn&#8217;t present, no redirecting will be done. If the REQUEST_URI isn&#8217;t present, the QUERY_STRING will be tried. If this doesn&#8217;t exist the client will be redirected to the root of the specified domain.</p>
<p><strong>A note about redirects:</strong> In this case, it&#8217;s really important that we send a <a title="HTTP Response Status Code 301" href="http://en.wikipedia.org/wiki/HTTP_301">301 Moved Permanently</a> response status code to the visiting client. If the visitor is a search bot, it &#8216;should&#8217; update any references to the other domain in its index.</p>
<p>If you have any questions, comments for corrections, please post below!</p>
]]></content:encoded>
			<wfw:commentRss>http://myquickfix.co.uk/index.php/2008/12/permanent-redirect-http-301-to-specific-domain-while-preserving-querystring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
