<?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>mikestreety &#187; PHP</title>
	<atom:link href="http://www.mikestreety.co.uk/category/php-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikestreety.co.uk</link>
	<description>happy, nerd, tweeter, developer, geek</description>
	<lastBuildDate>Sat, 19 May 2012 09:09:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>#PHPFED &#8211; Variables</title>
		<link>http://www.mikestreety.co.uk/2012/05/phpfed-variables/</link>
		<comments>http://www.mikestreety.co.uk/2012/05/phpfed-variables/#comments</comments>
		<pubDate>Fri, 18 May 2012 21:32:05 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPFED]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php for beginners]]></category>
		<category><![CDATA[php for front-end devs]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.mikestreety.co.uk/?p=574</guid>
		<description><![CDATA[Before you continue &#8211; make sure you understand the story. The next thing is that php lines always need to end with a semi-colon (;). This tells php that the line has finished and to run it. Without this you &#8230; <a href="http://www.mikestreety.co.uk/2012/05/phpfed-variables/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Before you continue &#8211; make sure you understand <a title="PHP for Front-End Devs: The Story" href="http://www.mikestreety.co.uk/2012/05/php-for-front-end-devs-the-story/">the story.</a></p>
<p>The next thing is that php lines always need to end with a semi-colon (;). This tells php that the line has finished and to run it. Without this you will experience &#8216;Unexpected&#8217; errors.</p>
<p>So lets get started. In a line &#8211; Variables let you store data, or a value, in a word. Its that simple.</p>
<p>e.g.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$m</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mikestreety'</span><span style="color: #339933;">;</span></div></div>
<p>Now I can freely use</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$m</div></div>
<p>anywhere else on the page and it would mean &#8216;mikestreety&#8217;.</p>
<p>You use this variable, you need to echo, or print out, the result. The are two basic ways to achieve this. You can do it the classic way:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$m</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>Or use the shorthand way:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$m</span><span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>The second method is shorthand for opening php tags and echoing out the result and is a lot cleaner if you&#8217;re using it inline, in html. But if you are already inside PHP tags, it makes sense to echo it.</p>
<p>Admittedly, this is a poor example of why you would use a variable, after all, why store a single word?</p>
<p>That is because variables are a lot more powerful than this, they can stores lists, they can help you connect to a database, loop through things, if statements &#8211; the list goes on. Variables are the very base of PHP and without them, PHP would be impossible.</p>
<p>So, lets look a practical example of a variable.</p>
<p>Say you have a link you regularly update on a homepage, but this link is in 4 different places. Rather than find and replace, or hunt around for them, you could declare them as a variable at the top, then use that throughout the document.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://mikestreety.co.uk&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$link</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;my blog&lt;/a&gt;</div></div>
<p>Variables can, on the simple level, store strings and numbers. A string is a piece of text and is put in either speech marks or inverted commas to mark the start and the end. (see the previous examples). With a string, you may find that it features an inverted comma, or a speech mark which is ending your string early, and then throwing an error. This can be avoided by whats known as escaping the character. The escape character immediately proceeds the troublesome character, to tell php to take it as a literal punctuation.</p>
<p>The escape character is simply the backslash. So say I have this as my code:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<span style="color: #000088;">$m</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div class=&quot;element&quot;&gt;don'</span>t go that way<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><span style="color: #0000ff;">';<br />
?&gt;</span></div></div>
<p>As you can see (thanks to the syntax highlighting plugin) it doesn&#8217;t fair well &#8211; as the single quote in the word don&#8217;t, is ending my string early.</p>
<p>The escaped version would look like this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<span style="color: #000088;">$m</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div class=&quot;element&quot;&gt;don\'t go that way&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>or if you use double quotes to encapsulate your sting:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<span style="color: #000088;">$m</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>element<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;don't go that way&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>PHP can also do maths and store numerical values:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$figure</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$figuretwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$figure</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$figuretwo</span> <span style="color: #666666; font-style: italic;">//will echo 12</span></div></div>
<p>Numerical values do not need to be stored as a string &#8211; hence the reason there is no single or double quotes.</p>
<p>That&#8217;s it for the very basics of the variable. It may seem a little odd on its own, but i&#8217;ll be covering more things it can do. Once you&#8217;ve understood the variable and that it can store things, PHP is wide open</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2012/05/phpfed-variables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>#PHPFED &#8211; Includes</title>
		<link>http://www.mikestreety.co.uk/2012/05/phpfed-includes/</link>
		<comments>http://www.mikestreety.co.uk/2012/05/phpfed-includes/#comments</comments>
		<pubDate>Thu, 10 May 2012 18:04:09 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPFED]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[includes]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php for beginners]]></category>
		<category><![CDATA[php for front-end devs]]></category>

		<guid isPermaLink="false">http://www.mikestreety.co.uk/?p=595</guid>
		<description><![CDATA[Before you continue &#8211; make sure you understand the story. When developing static sites (i.e. sites without any sort of CMS &#8211; be it WordPress, Drupal etc.) the PHP I find the most valuable  is the include. This allows you to &#8230; <a href="http://www.mikestreety.co.uk/2012/05/phpfed-includes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Before you continue &#8211; make sure you understand <a title="PHP for Front-End Devs: The Story" href="http://www.mikestreety.co.uk/2012/05/php-for-front-end-devs-the-story/">the story.</a></p>
<p>When developing static sites (i.e. sites without any sort of CMS &#8211; be it WordPress, Drupal etc.) the PHP I find the most valuable  is the <em>include</em>.</p>
<p>This allows you to simply include one file into another file. The file that you include can be anything, from txt to HTML. However, generally for constancy the most popular file type is PHP.</p>
<p>To do an include:</p>
<ul>
<li>Make sure the file you are working on is saved as .php extension</li>
<li>Make sure the file you are going to include is saved</li>
<li>Use the following code:</li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php include 'file.php'; ?&gt;
</pre>
<p>Its as simple as that! The include path needs to be relative. normal convention is to store the includes in a folder called &#8216;includes&#8217; in the root.</p>
<p>At first you might wonder what this is useful for? The main use would be to include the header, or the footer, of a website. This enables you to change 1 file and it update on all your pages, without having to do a mass find and replace.</p>
<p>You can also use it to help divide up a page &#8211; for easmple if you had a one page website with 5 sections, you could put each of those sections in its own include to help the one page becoming a big mess.</p>
<p>A small example page set up can be found on <a href="https://github.com/mikestreety/PHPFED/tree/master/includes">github</a>. Feel free to fork the blog post or code if you can thing of a better way to explain!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2012/05/phpfed-includes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Github for PC and setting up a local testing environment</title>
		<link>http://www.mikestreety.co.uk/2012/05/github-for-pc-and-setting-up-a-local-testing-environment/</link>
		<comments>http://www.mikestreety.co.uk/2012/05/github-for-pc-and-setting-up-a-local-testing-environment/#comments</comments>
		<pubDate>Sat, 05 May 2012 16:25:01 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[local environment]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[xampp]]></category>

		<guid isPermaLink="false">http://www.mikestreety.co.uk/?p=541</guid>
		<description><![CDATA[The Quick Way Install XAMPP If on Winows Vista or 7, install it in your user folder Install MySQL and Apache as a Service If after installation Ports 80 and 443 are busy open Skype, Options -&#62; Advanced -&#62; Connection &#8230; <a href="http://www.mikestreety.co.uk/2012/05/github-for-pc-and-setting-up-a-local-testing-environment/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>The Quick Way</h2>
<ul>
<li>Install <a href="http://www.apachefriends.org/en/xampp-windows.html">XAMPP</a></li>
<ul>
<li>If on Winows Vista or 7, install it in your user folder</li>
<li>Install MySQL and Apache as a Service</li>
<li>If after installation Ports 80 and 443 are busy open Skype, Options -&gt; Advanced -&gt; Connection -&gt; Uncheck the box</li>
</ul>
<li>Download and install <a href="http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git">Git for Windows</a></li>
<li>Download and install <a href="http://code.google.com/p/tortoisegit/">Tortoise Git</a></li>
<li>Open up PuTTY Gen and generate a key</li>
<li>Go to Github -&gt; Options -&gt; SSH Key -&gt; Add New and paste the long key from PuTTYGen into the box in Github. Name it something that represents your computer</li>
<li>Save the Private key somewhere as key.ppk</li>
<li>Navigate to folder where you want the repository, right click and select Git create repository here&#8230;</li>
<li>Right click again and go to TortoisGit -&gt; options</li>
<li>Select Git on the right hand side, fill in your name and email</li>
<li>Select Remote from the lef thand side</li>
<li>Fill in a name, the git URL (found at the top of the repository on Github) and browse for the private key you saved, Save.</li>
<li>Right click in the folder, tortoisegit -&gt; pull. Click ok</li>
<li>Edit Files.</li>
<li>Right click -&gt; commit to master</li>
<li>Click push on the bottom left of the screen once completed. Click ok.</li>
</ul>
<h2>The Long Way</h2>
<p>Unlike mac &#8211; there isn&#8217;t a simple &#8216;Github for Windows&#8217; application (at time of writing). However, setting up Github to work on your pc is fairly simple. More complicated than the mac app, but you do get more of an understanding about what git is.</p>
<p>This tutorial is not about what git is, its simply some instructions on how to get things working.Oh. and also &#8211; people do use windows machines for development. Deal with it.</p>
<p>With this tutorial, I&#8217;m going to go from start to finish &#8211; from setting up a local testing environment, right through to the github stage. If you already have something like xampp or wamp installed on your PC, you can skip the first bits.</p>
<h3>Setting Up A Local Environment</h3>
<p>HTML files work fine on a local machine, however, when you come to running PHP files, normal windows can&#8217;t handle it. For that reason you need to set up a local environment, or sever. This allows you to run PHP to your hearts content and even build databases if you want!</p>
<p>To do this, my recommendation is <a href="http://www.apachefriends.org/en/xampp-windows.html">XAMPP</a>. (Believe me &#8211; I tried them all. XAMPP is simple and easy but horrible looking).</p>
<p>Download the windows installer and follow the steps. If you are on Vista/Win 7 &#8211; i suggest installing it in C:\Users\YOUR USER\xampp as it sometimes struggles to install it on the C:\</p>
<p><img class="aligncenter size-full wp-image-548" title="xampp1" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/xampp1.png" alt="" width="553" height="450" /></p>
<p>Make sure both Apache and MySQL are installed as services. It makes life easier.</p>
<p><img class="aligncenter size-full wp-image-549" title="xampp2" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/xampp2.png" alt="" width="382" height="188" /></p>
<p>It takes a while to install. Go make a cup of tea or something.</p>
<p>When its installed and you start Apache, you may get a windows firewall message. Accept that.</p>
<p>You might find that after installation, it says it can&#8217;t start Apache bacause something is using the port. The main cause I&#8217;ve found is Skype. If you have it installed, open up the options, then advanced and then connection and uncheck the box that says about using port 80.</p>
<p><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/skype3.png"><img class="aligncenter size-full wp-image-547" title="skype3" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/skype3.png" alt="" width="339" height="33" /></a></p>
<p>All things being well you should be albe to navigate to http://localhost in your browser and view the files. The files are located in C:\Users\YOUR USER\xampp\htdocs</p>
<h3>Setting Up Git</h3>
<p>The next thing you need to do is download and install git.</p>
<p>Head over and download <a href="http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git">Git for Windows</a></p>
<p>The only thing to note is to set the option to &#8216;Run Git from the Windows Command Prompt&#8217;</p>
<p><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/git4.png"><img class="aligncenter size-full wp-image-550" title="git4" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/git4.png" alt="" width="503" height="388" /></a></p>
<p>The next step is to download and install <a href="http://code.google.com/p/tortoisegit/">Tortoise Git</a></p>
<p>When installing. make sure you tick &#8216;Tortoise Plink&#8217; on the option</p>
<p><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t5.png"><img class="aligncenter size-full wp-image-551" title="t5" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t5.png" alt="" width="421" height="143" /></a></p>
<p>Once the installation has finished, you won&#8217;t notice any change, except when you&#8217;re on a windows explorer window, there is some new options to the right click menu.</p>
<h3>Pulling, Committing and Pushing</h3>
<p>For this next bit i&#8217;m going to be pulling, editing, committing and pushing to my<a href="https://github.com/mikestreety/Foundation.less"> Foundation.less repository</a>.</p>
<p>Firstly, we need to generate some random keys, a public and a private one. These are used so that Github knows its you. The public key is used by Github to check against the private key you pass it when pushing.</p>
<p>To start go to Start -&gt; Programs -&gt; TortoiseGit -&gt; <strong>PuTTYGen</strong></p>
<p>On the right hand side, click Generate and wiggle your mouse around under the status bar to generate the two keys. Once done, don&#8217;t close the window!</p>
<p>Head to Github, log in and then click account settings and <a href="https://github.com/settings/ssh">SSH Keys</a> on the left. Click the <strong>Add SSH Key</strong>. Give the SSH key a name (i.e. the name of your computer) and then paste the big long key that the puttygen generated. (The &#8216;Public key for pasting into OpenSSH authorized_keys file:)</p>
<p>Once pasted in, hit <strong>save</strong>.</p>
<p>Head back to PuttyGen. You need to save the private key and feed it into TortoiseGit.You do this by entering a passphase if you want (makes it more secure), then clicking &#8216;<strong>Save Private Key</strong>&#8216;. Make sure you choose a good location, as you&#8217;ll need this everytime you want to make a new repository for Github. Save it as <strong>key.ppk</strong></p>
<p>Close PuTTYGen and head to the folder where your repository is going to be.</p>
<h2>Creating the Repository (Repeat for each repository)</h2>
<p>Navigate to a folder where you want the repository to reside. I&#8217;m all about neatness and want to keep all my repositories in one place, so have chosen <strong>C:\Users\mike\xampp\htdocs </strong>(The XAMPP location). That way I can run any PHP files that have been pulled. In there make a folder for the repository. It can be called anything but for constancy I&#8217;m naming it Foundation.less.</p>
<p>This folder can be <em>anywhere</em> on your machine.</p>
<p>Once inside the folder, right click and select the option<strong> Git Create repository here&#8230;</strong></p>
<p>Click OK on the first box without checking the box and you should then get an alert:</p>
<p><img class="aligncenter size-full wp-image-552" title="t7" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t7.png" alt="" width="574" height="152" /></p>
<p>If you have &#8216;<strong>show hidden files</strong>&#8216; turned on, you&#8217;ll see a hidden <strong>.git</strong> folder. If you want the folder to stop being a repository, just delete that.</p>
<p>Right click and go to TortoiseGit -&gt; Settings and then click &#8216;<strong>Git</strong>&#8216; on the left hand side. Fill in your name and your email &#8211; these are the credentials that will be used when pushing.</p>
<p><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t8.png"><img class="aligncenter size-full wp-image-553" title="t8" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t8.png" alt="" width="696" height="377" /></a></p>
<p>Next, click <strong>Remote</strong> (on the left, branching off of the selected &#8216;Git&#8217; option). Fill in the fields as follows:</p>
<p><strong>Remote: </strong>this is the name of your repository (can be anything)<br />
<strong>URL: </strong>This is the github URL provided at the top of your repository starting git@github.com&#8230;<br />
<strong>Putty Key: </strong>Navigate to you key.ppk file.</p>
<p style="text-align: center;"><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t9.png"><img class="aligncenter  wp-image-554" title="t9" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t9.png" alt="" width="600" /></a></p>
<p>Click <strong>Add New/Save</strong> and then OK at the bottom.</p>
<p>You should now be faced with the empty folder. Right click go to TortoiseGit and then click Pull (should be near the top). The Remote should be what you called it in the options. After clicking OK you might get a putty security alert, click yes and you can watch the tortoise do some acrobatics.</p>
<p><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t10.png"><img class="aligncenter size-full wp-image-555" title="t10" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t10.png" alt="" width="509" height="363" /></a></p>
<p>Once he&#8217;s done, you should see all your files in the folder, as they appear on Github.</p>
<h3>Editing and Pushing</h3>
<p>Once you&#8217;ve finished editing the files, Right click and select &#8216;<strong>Git Commit -&gt; &#8220;master</strong>&#8220;&#8216;.  A dialogue box will appear where you fill in what you&#8217;ve changed and you select the files to commit.</p>
<p><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t11.png"><img class="aligncenter size-full wp-image-556" title="t11" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t11.png" alt="" width="490" height="532" /></a></p>
<p>Once you&#8217;ve clicked <strong>OK</strong>, you&#8217;ll get another box showing the progress. Upon completion, click the <strong>Push</strong> button located in the bottom left of the box.</p>
<p>Click <strong>OK</strong> on the following dialogue and this pushes your changes to Github.</p>
<p><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t12.png"><img class="aligncenter size-full wp-image-557" title="t12" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t12.png" alt="" width="519" height="357" /></a></p>
<p><strong>Success!</strong></p>
<p style="text-align: center;"><a href="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t13.png"><img class="aligncenter  wp-image-558" title="t13" src="http://www.mikestreety.co.uk/wp-content/uploads/2012/05/t13.png" alt="" width="600" /></a></p>
<p>If you have any problems, or can suggest any changes to this blog, <a href="http://www.twitter.com/mikestreety">tweet me</a>, <a href="mailto:mikestreety@gmail.com">email me</a> or leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2012/05/github-for-pc-and-setting-up-a-local-testing-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strip out YouTube code from the URL</title>
		<link>http://www.mikestreety.co.uk/2011/08/strip-out-youtube-code-from-the-url/</link>
		<comments>http://www.mikestreety.co.uk/2011/08/strip-out-youtube-code-from-the-url/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 09:05:09 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[strip id]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[youtube code]]></category>
		<category><![CDATA[youtube id]]></category>
		<category><![CDATA[youtube video]]></category>

		<guid isPermaLink="false">http://codehorse.co.uk/?p=147</guid>
		<description><![CDATA[Big thanks to Kris Noble for this snippet of code. If you are setting up a CMS for a client which includes a video of sorts &#8211; you may wish to keep the ratio and dimensions, but allow them to &#8230; <a href="http://www.mikestreety.co.uk/2011/08/strip-out-youtube-code-from-the-url/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Big thanks to <a href="https://twitter.com/#!/simianstudios" target="_blank">Kris Noble</a> for this snippet of code.</p>
<p>If you are setting up a CMS for a client which includes a video of sorts &#8211; you may wish to keep the ratio and dimensions, but allow them to change the code through the CMS. This function below strips out the required code from the URL so that the client doesn&#8217;t have to. If the client does paste in just the code &#8211; it picks that up as well and uses it.</p>
<pre class="brush: php; title: ; notranslate">
function get_youtube_id($ytURL)
{
    // Adapted from http://snipplr.com/view.php?codeview&amp;id=19232

    $ytvIDlen = 11; // This is the length of YouTube's video IDs

    $ytURL = str_replace('http://youtu.be/', '', $ytURL);
    // Accounts for short youtube URL

    if(strlen($ytURL) == $ytvIDlen)
    {
        // probably already a valid id
        return $ytURL;
    }

    // The ID string starts after &quot;v=&quot;, which is usually right after
    // &quot;youtube.com/watch?&quot; in the URL
    $idStarts = strpos($ytURL, &quot;?v=&quot;);

    // In case the &quot;v=&quot; is NOT right after the &quot;?&quot; (not likely, but I like to keep my
    // bases covered), it will be after an &quot;&amp;&quot;:
    if($idStarts === FALSE)
    {
        $idStarts = strpos($ytURL, &quot;&amp;v=&quot;);
    }

    // If still FALSE, URL doesn't have a vid ID
    if($idStarts === FALSE)
    {
        // some kind of 'Please enter a valid YouTube video ID or URL' validation message here maybe..
        return FALSE;
    }

    // Offset the start location to match the beginning of the ID string
    $idStarts +=3;

    // Get the ID string and return it
    $ytvID = substr($ytURL, $idStarts, $ytvIDlen);

    return $ytvID;

}
</pre>
<p>For example, in your CMS you might have a field titled &#8216;Youtube Video&#8217; where the user pastes in the URL to the video.</p>
<p>On your front end you will then have code similar to this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php $videoID = get_youtube_id($youtubeVideo);
if($videoID) { ?&gt;
&lt;iframe width=&quot;357&quot; height=&quot;222&quot; src=&quot;http://www.youtube.com/embed/&lt;?=$videoID?&gt;&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;
&lt;?php } ?&gt;
</pre>
<p>In other words &#8211; if there is a youtube video content, show the above code and place the youtube video ID in the correct place.</p>
<p>Below is a minified version of the function</p>
<pre class="brush: php; title: ; notranslate">
		function get_youtube_id($ytURL)	{
			$ytvIDlen = 11;
			$ytURL = str_replace('http://youtu.be/', '', $ytURL);
			if(strlen($ytURL) == $ytvIDlen) {return $ytURL;}
			$idStarts = strpos($ytURL, &quot;?v=&quot;);
			if($idStarts === FALSE) { $idStarts = strpos($ytURL, &quot;&amp;v=&quot;);}
			if($idStarts === FALSE)	{ return FALSE;}
			$idStarts +=3;
			$ytvID = substr($ytURL, $idStarts, $ytvIDlen);
			return $ytvID;
			// Thanks to Kris Noble and http://snipplr.com/view.php?codeview&amp;id=19232 for this
		}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2011/08/strip-out-youtube-code-from-the-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iFrame Reveal Code/Like to Win/Like to Download Tab for Facebook</title>
		<link>http://www.mikestreety.co.uk/2011/08/iframe-reveal-codelike-to-winlike-to-download-tab-for-facebook/</link>
		<comments>http://www.mikestreety.co.uk/2011/08/iframe-reveal-codelike-to-winlike-to-download-tab-for-facebook/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 14:18:19 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://codehorse.co.uk/?p=143</guid>
		<description><![CDATA[This code is now no longer supported &#8211; a new blog post will be coming soon]]></description>
			<content:encoded><![CDATA[<p style="color: red; font-weight: bold;">This code is now no longer supported &#8211; a new blog post will be coming soon</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
  function parsePageSignedRequest() {
    if (isset($_REQUEST['signed_request'])) {
      $encoded_sig = null;
      $payload = null;
      list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
      $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
      return $data;
    }
    return false;
  }
  if($signed_request = parsePageSignedRequest()) {
    if($signed_request-&gt;page-&gt;liked) { ?&gt;

YOU LIKE THE PAGE

&lt;?php } else { ?&gt;

LIKE THE PAGE

&lt;?php } ?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2011/08/iframe-reveal-codelike-to-winlike-to-download-tab-for-facebook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Widgetizing a WordPress Sidebar and Creating an Additional One</title>
		<link>http://www.mikestreety.co.uk/2011/05/widgetizing-a-wordpress-sidebar-and-creating-an-additional-one/</link>
		<comments>http://www.mikestreety.co.uk/2011/05/widgetizing-a-wordpress-sidebar-and-creating-an-additional-one/#comments</comments>
		<pubDate>Thu, 05 May 2011 16:29:42 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[adding widgets]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[widgets]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://codehorse.co.uk/?p=91</guid>
		<description><![CDATA[When developing a WordPress theme, you may wish to take advantage of the built in system to manage, edit and order the sidebar widgets. Many themes have this built in, but if you&#8217;re developing from scratch, you might not have &#8230; <a href="http://www.mikestreety.co.uk/2011/05/widgetizing-a-wordpress-sidebar-and-creating-an-additional-one/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When developing a WordPress theme, you may wish to take advantage of the built in system to manage, edit and order the sidebar widgets. Many themes have this built in, but if you&#8217;re developing from scratch, you might not have the code to implement it.</p>
<p>First, locate your functions.php. This can be found in:</p>
<p><strong>wp-contentthemesYOUR THEME NAMEfunctions.php</strong></p>
<p>If this file doesn&#8217;t exist, then simply make one starting and finishing with the standard php tags</p>
<p><?php</p>
<p>?></p>
<p>In between the php tags, paste the following code:</p>
<p>[PHP]<br />
/* ADDING SIDEBAR WIDGETS FUNCTIONS */<br />
if ( function_exists(&#8216;register_sidebar&#8217;) )<br />
    register_sidebar(array(<br />
	&#8216;before_widget&#8217; => &#8216;
<div id="%1$s" class="widget box %2$s">&#8216;, //what each widget instance is wrapped in<br />
    &#8216;after_widget&#8217; => &#8216;</div>
<p>&#8216;, //closing tag of the above<br />
	&#8216;before_title&#8217; => &#8216;<br />
<h3>&#8216;, //what the widget title is wrapped in<br />
     &#8216;after_title&#8217; => &#8216;</h3>
<p>&#8216;, //closing tag of the above<br />
	));<br />
[/PHP]</p>
<p>This code (commented appropriately) is what wraps the widget and it&#8217;s heading. The %2$s adds a class specific to the widget.</p>
<p>Next, head to sidebar.php or wherever you want your widgets to appear. Paste in the following code:</p>
<p>[HTML]</p>
<div class="sidebar">
		<?php if ( !function_exists('dynamic_sidebar')<br />
        || !dynamic_sidebar() ) : ?><br />
<!-- alternative content  --><br />
		<?php endif; ?>
</div>
<p>[/HTML]</p>
<p>The alternative content will only appear if there are no widgets in the sidebar.</p>
<p>If you want to create a second widget section (be it in your footer, or in a second sidebar) then you will need the following code in your functions.php</p>
<p>[PHP]<br />
if ( function_exists(&#8216;register_sidebar&#8217;) )<br />
    register_sidebar(array(<br />
	&#8216;name&#8217;=>&#8217;after_posts&#8217;,<br />
	&#8216;before_widget&#8217; => &#8216;
<div id="%1$s" class="widget box %2$s">&#8216;,<br />
    &#8216;after_widget&#8217; => &#8216;</div>
<p>&#8216;,<br />
	&#8216;before_title&#8217; => &#8216;<br />
<h3>&#8216;,<br />
     &#8216;after_title&#8217; => &#8216;</h3>
<p>&#8216;,<br />
	));<br />
[/PHP]</p>
<p>The only new code here is &#8216;name&#8217;. Which tells WordPress what the name of your new sidebar is. Now head over to the file where you want this second widget section to be and paste in the following code:</p>
<p>[HTML]<br />
<?php if ( !function_exists('dynamic_sidebar')<br />
        || !dynamic_sidebar('after_posts') ) : ?><br />
		<?php endif; ?><br />
[/HTML]</p>
<p>Change &#8216;after_posts&#8217; in both bits of code accordingly and you are good to go!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2011/05/widgetizing-a-wordpress-sidebar-and-creating-an-additional-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limit Items (e.g. News posts)</title>
		<link>http://www.mikestreety.co.uk/2011/03/limit-items-e-g-news-posts/</link>
		<comments>http://www.mikestreety.co.uk/2011/03/limit-items-e-g-news-posts/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 14:59:59 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[slice]]></category>

		<guid isPermaLink="false">http://codehorse.co.uk/?p=65</guid>
		<description><![CDATA[If you would like to limit the amount of items coming out of an array (for example the first 5 news items), then before your loop (e.g. while), specify your start and finish points [PHP] $A = array_slice($A, START, END); &#8230; <a href="http://www.mikestreety.co.uk/2011/03/limit-items-e-g-news-posts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you would like to limit the amount of items coming out of an array (for example the first 5 news items), then before your loop (e.g. while), specify your start and finish points</p>
<p>[PHP]<br />
$A = array_slice($A, START, END);<br />
while $A {<br />
[/PHP]</p>
<p>For example, if you did want to only pull out the first 5 news items in an array, you would:</p>
<p>[PHP]<br />
$news_items = array_slice($news_items, 0, 5);<br />
while $news_items {<br />
[/PHP] </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2011/03/limit-items-e-g-news-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get an &#8216;Even&#8217; Class</title>
		<link>http://www.mikestreety.co.uk/2011/02/get-an-even-class/</link>
		<comments>http://www.mikestreety.co.uk/2011/02/get-an-even-class/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 14:31:09 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[if statement]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://codehorse.co.uk/?p=48</guid>
		<description><![CDATA[This simple PHP statement applies class=&#8221;even&#8221; to every other element when in a loop. I often use this on tables to get an even class to help devide up the rows, but it can also be used to add a &#8230; <a href="http://www.mikestreety.co.uk/2011/02/get-an-even-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This simple PHP statement applies class=&#8221;even&#8221; to every other element when in a loop.</p>
<p>I often use this on tables to get an even class to help devide up the rows, but it can also be used to add a class to the 4th item in a list (if you want to remove certain margin/padding for example).</p>
<p>To start, &#8216;clear&#8217; i and make it 0. (if $i is already used elsewhere in your code, you can replace it with anything)</p>
<p>[PHP]$i=0;[/PHP]</p>
<p>Then once in the loop, use/adapt the following code to achieve the desired result (have broken it up into seperate lines to add comments. The single line code is included after)</p>
<p>[PHP]<br />
<?php<br />
     echo $i++ % 2 ?       //if $i divided by 2 has no remainder<br />
          ' class="even"' :   //then echo this result<br />
         '';                         //if not echo this result<br />
?><br />
[/PHP]</p>
<p>the number 2 can be replaced with what ever number item you want the class. And if you already have existing classes on your item, then remove the <em>class=&#8221;"</em> and just have the class name.</p>
<p>The code as a single line:</p>
<p>[PHP]<br />
<?php echo $i++ % 2 ? ' class="even"' : ''; ?><br />
[/PHP] </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2011/02/get-an-even-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Giving something a &#8216;Last&#8217; Class</title>
		<link>http://www.mikestreety.co.uk/2011/02/giving-something-a-last-class/</link>
		<comments>http://www.mikestreety.co.uk/2011/02/giving-something-a-last-class/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 10:27:32 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[last class]]></category>
		<category><![CDATA[last one]]></category>
		<category><![CDATA[last row]]></category>
		<category><![CDATA[list item]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://codehorse.co.uk/?p=43</guid>
		<description><![CDATA[If you want to apply a different class to the last item in a list generated by PHP, start off with Setting the $lastOne variable to the end of your list This stores the details of the last one in &#8230; <a href="http://www.mikestreety.co.uk/2011/02/giving-something-a-last-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to apply a different class to the last item in a list generated by PHP, start off with Setting the $lastOne variable to the end of your list</p>
<pre class="brush: php; title: ; notranslate">$lastOne = end($A);</pre>
<p>This stores the details of the last one in your list into the lastOne variable &#8211; we&#8217;ll compare later.</p>
<p>You may need to modify your existing while/foreach loop, adding in the $i variable to your item. If i is already used, then pick any other letter.</p>
<pre class="brush: php; title: ; notranslate">foreach($A as $i =&gt; $B){</pre>
<p>Then on the list item or table row that you want to apply the last class to, compare your $lastOne with the current one your are looping through.</p>
<pre class="brush: php; title: ; notranslate">&lt;?=$lastOne==$B?' class=&quot;last&quot;':''?&gt;</pre>
<p>To give you an real life example, the below was used on a project while listing out related categories to the one the user was currently browsing. We experienced a recurrence loop and so to overcome this, we simply compare the unique ID (primary key) field for ease and to bypass any problems</p>
<pre class="brush: php; title: ; notranslate">$lastOne = end($relatedCategories);
foreach($relatedCategories as $i =&gt; $relCat){

&lt;?=$lastOne-&gt;uid==$relCat-&gt;uid?' last':''?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2011/02/giving-something-a-last-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Develop, Style or Add Content to a Live Site</title>
		<link>http://www.mikestreety.co.uk/2010/12/develop-and-style-something-on-a-live-site/</link>
		<comments>http://www.mikestreety.co.uk/2010/12/develop-and-style-something-on-a-live-site/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 15:01:17 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[adding content]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redirecting]]></category>
		<category><![CDATA[secret links]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://codehorse.co.uk/?p=29</guid>
		<description><![CDATA[If you want to develop/edit something on a live website, but you want to send a preview to a client, it can sometimes be tricky weighing up where and how to do it. If your website is PHP, there is &#8230; <a href="http://www.mikestreety.co.uk/2010/12/develop-and-style-something-on-a-live-site/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to develop/edit something on a live website, but you want to send a preview to a client, it can sometimes be tricky weighing up where and how to do it. </p>
<p>If your website is PHP, there is a simple piece of code you can implement to send someone a test URL. Copy and paste the below code into wherever you need to add/change.</p>
<pre class="brush: php; title: ; notranslate">&lt;?php if($_SERVER['QUERY_STRING'] == 'test') {  ?&gt;
&lt;!-- code protected from public viewing --&gt;
&lt;?php } ?&gt;</pre>
<p>You can put anything in between the PHP, Including CSS, HTML and PHP. If you need to replace something rather than add, simply adapt it to be an ELSE statement like so:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php if($_SERVER['QUERY_STRING'] == 'test') {  ?&gt;
&lt;!-- code protected from public viewing --&gt;
&lt;?php } else { ?&gt;
&lt;!-- Original Code --&gt;
&lt;?php } ?&gt;
</pre>
<p>To access the extra content, navigate to <strong>www.yoursite.com/anypage?test</strong>. To change &#8216;?test&#8217; to any other word, edit the first line of the PHP.</p>
<p>This is also helpful for use with contact forms (sending the user back to your contact page with ?thanks in the URL or similar and replacing the contact form with a message), or sending users to different links on the same page to reveal codes or links.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikestreety.co.uk/2010/12/develop-and-style-something-on-a-live-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

