<?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>Ross Tanner</title>
	<atom:link href="http://rosstanner.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://rosstanner.co.uk</link>
	<description>Web Developer Gloucestershire</description>
	<lastBuildDate>Fri, 18 May 2012 15:52:36 +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>Parsing XML using PHP SimpleXML</title>
		<link>http://rosstanner.co.uk/2012/05/parsing-xml-php-simplexml/</link>
		<comments>http://rosstanner.co.uk/2012/05/parsing-xml-php-simplexml/#comments</comments>
		<pubDate>Fri, 18 May 2012 15:50:35 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[parse xml]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[XMLReader]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=428</guid>
		<description><![CDATA[<p>XML is amazing for transferring data between two systems and I use it on a daily basis. It took me a while to understand the need for it but once you start using XML, web services, APIs and general development will become clear to you. Today I will walk you through the basics of SimpleXML [...]]]></description>
			<content:encoded><![CDATA[<p>XML is amazing for transferring data between two systems and I use it on a daily basis. It took me a while to understand the need for it but once you start using XML, web services, APIs and general development will become clear to you. Today I will walk you through the basics of SimpleXML and how it can help you parse XML to make your applications more efficient.</p>
<p>Firstly you need to be aware of a downside to SimpleXML and this is that it is not very efficient for large XML files (when I say large I&#8217;m talking hundreds of megabytes and above). This is because SimpleXML will load the entire into XML document into memory before parsing it. So, you either need to increase PHP&#8217;s memory limit (not always advised) or use an alternative method, such as <a title="XMLReader" href="http://www.php.net/manual/en/book.xmlreader.php">XMLReader</a>.</p>
<p>Lets take a very simple XML document which happens to be called <strong>data.xml</strong>:</p>
<pre name="code" class="xml">    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;products&gt;
        &lt;product&gt;
            &lt;id&gt;1&lt;/id&gt;
            &lt;name&gt;Apple iPhone&lt;/name&gt;
            &lt;price&gt;500.00&lt;/price&gt;
        &lt;/product&gt;
        &lt;product&gt;
            &lt;id&gt;2&lt;/id&gt;
            &lt;name&gt;BlackBerry Curve&lt;/name&gt;
            &lt;price&gt;250.00&lt;/price&gt;
        &lt;/product&gt;
        &lt;product&gt;
            &lt;id&gt;2&lt;/id&gt;
            &lt;name&gt;Samsung Galaxy S&lt;/name&gt;
            &lt;price&gt;340.00&lt;/price&gt;
        &lt;/product&gt;
    &lt;/products&gt;</pre>
<p>You can see that there are a list of products and there are 3 individual items inside this tag. What we will do is load this file into SimpleXML which will convert into an object which we can then use for our application. Here is how we do this:</p>
<pre name="code" class="php">    &lt;?php

        // load the XML document into an Object
        $xml = simplexml_load_file ( "data.xml" );

    ?&gt;</pre>
<p>We now have our XML into an object which is stored in the variable <strong>$xml</strong>. If we output this to the browser we will see the following:</p>
<p><center style="clear: both; margin: 10px 0;"><a href="http://rosstanner.co.uk/wp-content/uploads/2012/05/simplexml.png"><img class="size-full wp-image-429 aligncenter" title="SimpleXML" src="http://rosstanner.co.uk/wp-content/uploads/2012/05/simplexml.png" alt="SimpleXML" width="390" height="458" /></a></center>This makes it much easier to see what&#8217;s going on in our XML document and it splits up quite well. We can see here that there are 3 products and also that each have an ID field, a name and price. Now let&#8217;s start parsing this data:</p>
<pre name="code" class="xml">
    &lt;?php

        // load the XML document into an Object
        $xml = simplexml_load_file ( "data.xml" );

        // loop through each product
        foreach ( $xml-&gt;product as $product ) {

            // output the product information
            echo "&lt;p&gt;";
            echo "&lt;strong&gt;".$product-&gt;name."&lt;/strong&gt;&lt;br /&gt;";
            echo "£".$product-&gt;price."&lt;/p&gt;";

        }

    ?&gt;</pre>
<p>Now you will see each product being output with the price beneath. This is just a simple example of parsing XML but of course there is much more you can do like build web services and such like. You would probably store the data into a database and output it that way as opposed to loading the XML on the fly, but it reallt depends on the application.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/05/parsing-xml-php-simplexml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding functions in PHP</title>
		<link>http://rosstanner.co.uk/2012/05/understanding-functions-in-php/</link>
		<comments>http://rosstanner.co.uk/2012/05/understanding-functions-in-php/#comments</comments>
		<pubDate>Tue, 01 May 2012 20:30:04 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[repeating code]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=413</guid>
		<description><![CDATA[<p>Well it&#8217;s been a while since I last posted so I needed to get back into it somewhat quickly and easily. No easier way than writing a quick PHP tutorial which will also help fellow both professional and freelance web developers.</p> <p>In today&#8217;s tutorial I am going to teach you how to create a function [...]]]></description>
			<content:encoded><![CDATA[<p>Well it&#8217;s been a while since I last posted so I needed to get back into it somewhat quickly and easily. No easier way than writing a quick PHP tutorial which will also help fellow both professional and freelance web developers.</p>
<p>In today&#8217;s tutorial I am going to teach you how to create a function in PHP. Functions are incredibly useful because they help organise your code, prevent repetitive coding and are the foundations behind a decent codebase. I use PHP functions in everyday coding and so do you, probably without even realising it. PHP has a number of built-in functions which you would have been using all the time, from strtolower() to mysql_connect() or perhaps even as advanced as preg_match(). Each function has it&#8217;s own use and as you learn more PHP you will become familiar with both built-in functions and making your own.</p>
<p>Before you go about creating functions there are a couple of questions that you need to ask yourself first:</p>
<ol>
<li>is there a function that already does what I want to do?</li>
<li>do I need to create a function? i.e is this code going to be repeated?</li>
</ol>
<p>If you still feel you need to create one then here is how you go about doing it. My example is incredibly simple and will basically take any number you pass through and multiply it by 5.</p>
<pre name="code" class="php">
&lt;?php
    function multiply_number ( $mynum )
    {
        $mynum = ( $mynum * 5 );
        return $mynum;
    }
?&gt;
</pre>
<p>You can see here that I have declared a new function called <strong>multiply_number</strong> and I am picking up whatever number is passed to the function. I am storing this passed number as <strong>$mynum</strong> and then multiplying that amount by 5 before returning the result. There are two clear benefits here:</p>
<ol>
<li>if I wanted to change 5 to any other number I can do it easily by changing it in only one place</li>
<li>if I am multiplying several numbers by 5 then its easier to keep calling this function rather than writing it out each time</li>
</ol>
<p>So, when we go about calling this function several times we can do it easily as follows:</p>
<pre name="code" class="php">
&lt;?php
    echo multiply_number(1);
    echo multiply_number(10);
    echo multiply_number(145);
    echo multiply_number(1563654);
    echo multiply_number(1.2);
?&gt;
</pre>
<p>I&#8217;m calling the function each time but just passing a different number. As the number is changing so will the result and this will be shown once the script has run. You could even expand this by passing a second number to the function and this number replaces the 5 &#8211; the number multiplied against.</p>
<p>Functions are incredibly useful and are a fundemental part of any master coder&#8217;s work, especially as you go into OOP (Object Orientated Programming) and the MVC (Model-View-Controller) structure.</p>
<p>I hope you found this useful. Please feel free to ask any questions or leave a comment below. <strong>Before anyone says &#8216;it would be quicker to just do the math each time&#8217; then yes, you are right. This is a very basic example of how functions can be used but as you keep developing you will learn to only use them when you know the time is right.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/05/understanding-functions-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Joomla &#8211; Remove index.php from URL</title>
		<link>http://rosstanner.co.uk/2012/02/joomla-remove-index-php-url/</link>
		<comments>http://rosstanner.co.uk/2012/02/joomla-remove-index-php-url/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 21:40:45 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[Joomla]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[mod rewrite]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=377</guid>
		<description><![CDATA[<p>A common question with pretty much any content management system software is &#8216;How do I remove index.php from the URL&#8217;. In most cases it is pretty simple and Joomla works similar to WordPress except better because they give you the standard .htaccess file (what is needed to route the right webpage to the right place). [...]]]></description>
			<content:encoded><![CDATA[<p>A common question with pretty much any content management system software is &#8216;How do I remove index.php from the URL&#8217;. In most cases it is pretty simple and Joomla works similar to WordPress except better because they give you the standard .htaccess file (what is needed to route the right webpage to the right place). You will probably be wondering why these CMS actually bother leaving the index.php in there in the first place. The answer is quite simple &#8211; they don&#8217;t know your server configuration.</p>
<p>A standard installation of Joomla with always (assuming the obvious system is in place) work as expected with a fresh install. As Windows and Linux servers work differently, so does URL rewriting. With Linux this requires a file called <em>.htaccess</em> and the <em>module mod_rewrite</em> and with a Windows server setup this requires something slightly different. Make sure you check which configuration you will be using.</p>
<p>So how do we go about doing this with our Joomla installation. All you need to do is (I am using Joomla 2.5.1):</p>
<ol>
<li>Go into your Joomla administration panel.</li>
<li>Select <strong>Site</strong> > <strong>Global Configuration</strong></li>
<li>Under <strong>SEO Settings</strong> set <strong>Use URL Rewriting</strong> to <strong>Yes</strong></li>
<li>Click <strong>Save</strong></li>
</ol>
<p>The next step is to rename the <strong>htaccess.txt</strong> file that came with the installation to <strong>.htaccess</strong> (notice there is no file extension &#8211; or no file name if you like &#8211; depends how you look at it). That is it, you are good to go. But what if you didn&#8217;t have a htaccess.txt file? No worries, you can use mine:</p>
<pre name="code" class="sql">
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
</pre>
<p>Any questions please leave a comment below and I will be happy to help.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/02/joomla-remove-index-php-url/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Google UK Easter Egg &#8211; Hello to Jason Isaacs</title>
		<link>http://rosstanner.co.uk/2012/02/google-uk-easter-egg-hello-to-jason-isaacs/</link>
		<comments>http://rosstanner.co.uk/2012/02/google-uk-easter-egg-hello-to-jason-isaacs/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 11:42:04 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[Search Engines]]></category>
		<category><![CDATA[bbc]]></category>
		<category><![CDATA[daniel radcliffe]]></category>
		<category><![CDATA[danny dyer]]></category>
		<category><![CDATA[david tennant]]></category>
		<category><![CDATA[easter egg]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[harry potter]]></category>
		<category><![CDATA[jason isaacs]]></category>
		<category><![CDATA[matt kermode]]></category>
		<category><![CDATA[michael sheen]]></category>
		<category><![CDATA[radio 5 live]]></category>
		<category><![CDATA[simon mayo]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=364</guid>
		<description><![CDATA[<p>Anyone who has performed a search for &#8220;<a title="Hello to Jason Isaacs" href="http://www.google.co.uk/?q=jason+isaacs#hl=en&#38;output=search&#38;sclient=psy-ab&#38;q=jason+isaacs&#38;pbx=1&#38;oq=&#38;aq=&#38;aqi=&#38;aql=&#38;gs_sm=&#38;gs_upl=&#38;bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&#38;fp=28b479b56846d329&#38;biw=1680&#38;bih=935" target="_blank">Jason Isaacs</a>&#8221; on <a title="Google UK - Hello to Jason Isaacs" href="http://www.google.co.uk/?q=jason+isaacs" target="_blank">Google.co.uk</a> will have already seen this. Those who haven&#8217;t heard <a title="BBC Radio 5 Live - Film Review Show" href="http://www.bbc.co.uk/programmes/b00lvdrj" target="_blank">BBC Radio 5 Live&#8217;s Film Review Show</a> in a while [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone who has performed a search for &#8220;<a title="Hello to Jason Isaacs" href="http://www.google.co.uk/?q=jason+isaacs#hl=en&amp;output=search&amp;sclient=psy-ab&amp;q=jason+isaacs&amp;pbx=1&amp;oq=&amp;aq=&amp;aqi=&amp;aql=&amp;gs_sm=&amp;gs_upl=&amp;bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&amp;fp=28b479b56846d329&amp;biw=1680&amp;bih=935" target="_blank">Jason Isaacs</a>&#8221; on <a title="Google UK - Hello to Jason Isaacs" href="http://www.google.co.uk/?q=jason+isaacs" target="_blank">Google.co.uk</a> will have already seen this. Those who haven&#8217;t heard <a title="BBC Radio 5 Live - Film Review Show" href="http://www.bbc.co.uk/programmes/b00lvdrj" target="_blank">BBC Radio 5 Live&#8217;s Film Review Show</a> in a while probably won&#8217;t understand what this actually means. Have a quick search using the link above then come back to read what this means or just check out the screen grab below.</p>
<div id="attachment_368" class="wp-caption aligncenter" style="width: 600px"><a href="http://rosstanner.co.uk/wp-content/uploads/2012/02/hello-to-jason-isaacs.jpg"><img class="size-full wp-image-368" title="Hello to Jason Isaacs" src="http://rosstanner.co.uk/wp-content/uploads/2012/02/hello-to-jason-isaacs.jpg" alt="Hello to Jason Isaacs" width="590" height="368" /></a><p class="wp-caption-text">Hello to Jason Isaacs - Google UK search</p></div>
<p>The story is that on one day live on air <a title="Simon Mayo" href="http://en.wikipedia.org/wiki/Simon_Mayo" target="_blank">Simon Mayo</a> (radio presenter) and <a title="Matt Kermode" href="http://en.wikipedia.org/wiki/Mark_Kermode" target="_blank">Matt Kermode</a> (film critic) decided to say &#8220;Hello&#8221; to one of Mark&#8217;s school friends, <a href="http://en.wikipedia.org/wiki/Jason_Isaacs" target="_blank">Jason Isaacs</a> (Harry Pitter film actor &#8211; Lucius Malfoy), live on their <a title="Matt Kermods and Simon Mayo's Film Review Show" href="http://en.wikipedia.org/wiki/Kermode_and_Mayo%27s_Film_Reviews" target="_blank">film review show</a>. Since then the duo have said &#8220;Hello&#8221; to a number of film actors such as <a title="Michael Sheen" href="http://en.wikipedia.org/wiki/Michael_Sheen" target="_blank">Michael Sheen</a>, <a title="David Tennant" href="http://en.wikipedia.org/wiki/David_tennant" target="_blank">David Tennant</a> and <a title="Danny Dyer" href="http://en.wikipedia.org/wiki/Danny_Dyer" target="_blank">Danny Dyer</a>. The simple yet effective slogan is shouted out whether Isaacs is on the show or not and has became a hit with many listeners. Jason has said himself that he replies with &#8220;Hello boys!&#8221; wherever he is in the world.</p>
<p>On the most recent show <a title="Harry Potter" href="http://en.wikipedia.org/wiki/Harry_Potter" target="_blank">Harry Potter</a> actor <a title="Daniel Radcliffe" href="http://en.wikipedia.org/wiki/Daniel_Radcliffe" target="_blank">Daniel Radcliffe</a> said &#8220;Hello to Jason Isaacs&#8221; and threw in a couple of personal comments for good measure, some not so good. To say it was slightly awkward was an understatement. However, the comedic side of the conversation has helped boost the hit and has spread very quickly across social media platforms.</p>
<p>There has even been a website created for it (<a title="Hello to Jason Isaacs" href="http://www.hellotojasonisaacs.com/">http://www.hellotojasonisaacs.com/</a>), you can buy numerous novelty items around the internet and of course Google has, as ever, joined in with a good sense of humour. It&#8217;s good to see these kind of easter eggs thrown in by Google, especially on St. Valentine&#8217;s Day. I wonder if the programmer who added this result into the search page actually had it signed off? Who knows (nobody probably). This only works on Google UK though, so check you aren&#8217;t on Google.com when looking for it.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/02/google-uk-easter-egg-hello-to-jason-isaacs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &amp; SEO &#8211; Permanent redirect using PHP header &#8211; HTTP 301</title>
		<link>http://rosstanner.co.uk/2012/01/php-seo-permanent-redirect-php-header/</link>
		<comments>http://rosstanner.co.uk/2012/01/php-seo-permanent-redirect-php-header/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 11:16:54 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[googlebot]]></category>
		<category><![CDATA[http 301]]></category>
		<category><![CDATA[permanent redirect]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[rosstanner]]></category>
		<category><![CDATA[search engine optimisation]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[seo friendly]]></category>
		<category><![CDATA[web development gloucestershire]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=355</guid>
		<description><![CDATA[<p>Permanent redirects are an important tool not only for general PHP development but also for Search Engine Optimisation. To a general user the browser simply forwards on to the new URL, probably without you even noticing. To search engine crawlers they are also forwarded but provided extra information that the page they are visiting has [...]]]></description>
			<content:encoded><![CDATA[<p>Permanent redirects are an important tool not only for general PHP development but also for Search Engine Optimisation. To a general user the browser simply forwards on to the new URL, probably without you even noticing. To search engine crawlers they are also forwarded but provided extra information that the page they are visiting has permanently moved to the new address. If this was Google for example, Googlebot would notice the change and drop the old URL from it&#8217;s index and begin indexing the new one.</p>
<p>So, what&#8217;s the point in a 301 permanent redirect and how does it differ to a standard redirect? If you needed to change the way a URL is structured from, for example, index.php?page=1 (very non-SEO friendly) to /web-development-gloucestershire/ (SEO friendly) then you can inform search engines of the change. Without the permanent redirect the first page will either fail and produce a &#8217;404 Not Found&#8217; or be identical to the new page &#8211; thus causing duplicate content issues.</p>
<p>The permanent redirect differs from a standard redirect because of the way it is informing search engines of the change. Without this it would become a temporary redirect or standard redirect. This means that search engines will keep the original page in it&#8217;s index because it is expecting the redirect to be removed at some point soon.</p>
<p>To create a 301 permanent redirect in PHP you use the following two lines of code, it&#8217;s really that easy.</p>
<pre name="code" class="php">&lt;?php
    header('HTTP/1.1 301 Moved Permanently');
    header('http://rosstanner.co.uk/');
?&gt;</pre>
<p>Remember, this must be placed at the very top of the script. More specifically, before any HTML content or output is produced. This is because PHP uses the headers, which are called before any output, in order to complete the redirect.</p>
<p><strong>Is there a limit on how many 301 redirects I can use on my website?</strong></p>
<p>In short the answer is no, there isn&#8217;t a limit. However there is a limit on &#8216;chained redirects&#8217; as Matt Cutts from Google explains.</p>
<hr />
<center><iframe width="560" height="315" src="http://www.youtube.com/embed/r1lVPrYoBkA" frameborder="0" allowfullscreen></iframe></center></p>
<hr />
<p>If you are running an Apache server you can achieve this using .htaccess too. If you don&#8217;t have access to edit this file within your online files then consult your webmaster.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/01/php-seo-permanent-redirect-php-header/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The &#8216;Your SIM card has a name&#8217; Facebook trick</title>
		<link>http://rosstanner.co.uk/2012/01/the-your-sim-card-has-a-name-facebook-trick/</link>
		<comments>http://rosstanner.co.uk/2012/01/the-your-sim-card-has-a-name-facebook-trick/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 11:52:19 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[cell phone]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook scams]]></category>
		<category><![CDATA[facebook trick]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=345</guid>
		<description><![CDATA[<p>You may have recently seen on Facebook a lot of people posting a &#8216;trick&#8217; that they have discovered/seen whereby posting a short snippet of code reveals the &#8216;name&#8217; of your cell phone or SIM card based on the last three digits of your phone number. Whilst this does produce a name it is totally unrelated [...]]]></description>
			<content:encoded><![CDATA[<p>You may have recently seen on Facebook a lot of people posting a &#8216;trick&#8217; that they have discovered/seen whereby posting a short snippet of code reveals the &#8216;name&#8217; of your cell phone or SIM card based on the last three digits of your phone number. Whilst this does produce a name it is totally unrelated to your mobile number.</p>
<p>Here is the trick that you would have seen and probably tried since you are here reading about it.</p>
<hr />
<code>Every SIM CARD has a name. Try this:</p>
<p>1st step : from your mobile number number, take the last 3 numbers. Example-07800 969684, take "684"only</p>
<p>2nd step: Write this @*[684:0] in the comment box below, replacing the 3 numbers with your own.</p>
<p>3rd step: remove the * sign and press enter in the comment box</code></p>
<hr />
Due to the way telephone numbers are generated, more than one person can have the same last 3 digits. Therefore claiming your unique phone number has it&#8217;s own name is nonsense.</p>
<p>So how is this happening? Basically the number you provide corresponds to an actual user&#8217;s ID on Facebook. It is not limited to three characters either. The code you enter into the comment box is a Facebook short-hand code that converts an ID number into it&#8217;s corresponding name. If you were to enter the code <code>@[4:0]</code> then this will present back &#8216;Mark Zuckerberg&#8217; since he was the first ID to use the website (1-3 were used for testing I believe). By using just three digits you are picking a random Harvard student who were the first users of the social networking site. You can even check this by going to the following URL and replacing <strong>123</strong> with the number that you are using.</p>
<p>http://www.facebook.com/profile.php?id=<strong>123</strong></p>
<p>Although the code works and is perhaps fun to use it is in no way related to a cell phone, mobile phone, SIM card or anything similar. It isn&#8217;t dangerous either (virus or spyware) so use it to your heart&#8217;s content.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/01/the-your-sim-card-has-a-name-facebook-trick/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial &#8211; Get your Twitter statuses</title>
		<link>http://rosstanner.co.uk/2012/01/php-tutorial-twitter-statuses/</link>
		<comments>http://rosstanner.co.uk/2012/01/php-tutorial-twitter-statuses/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 00:01:01 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[hash tags]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[REST API]]></category>
		<category><![CDATA[social media]]></category>
		<category><![CDATA[social networking]]></category>
		<category><![CDATA[trends]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=320</guid>
		<description><![CDATA[<p><a href="http://twitter.com/" target="_blank">Twitter</a> has fast become one of the most powerful social media platforms along with it&#8217;s great rival <a href="http://www.facebook.com/" target="_blank">Facebook</a> and the newcomer to the scene &#8211; <a href="http://plus.google.com" target="_blank">Google+</a>. Twitter is easily the best platform for companies and people &#8220;looking to be found&#8221; due to it&#8217;s potential reach. The hash tags, trends [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/" target="_blank">Twitter</a> has fast become one of the most powerful social media platforms along with it&#8217;s great rival <a href="http://www.facebook.com/" target="_blank">Facebook</a> and the newcomer to the scene &#8211; <a href="http://plus.google.com" target="_blank">Google+</a>. Twitter is easily the best platform for companies and people &#8220;looking to be found&#8221; due to it&#8217;s potential reach. The hash tags, trends and search functionality makes it possible for one person in England to see the tweets of someone in Venezuela (most random country I could think of!). This wouldn&#8217;t be possible with Facebook due to it&#8217;s networking &#8220;restrictions&#8221; and also you may have to be friends with that person first. Facebook also exposes A LOT more personal information making Twitter by far the better platform for promoting blog posts, discussing trends and communicating with other people in your niche market.</p>
<p>Having a section on your website with your tweets or even tweets from every employee in your company is becoming a very popular choice amongst web builders and agencies. It aids with the promotion of your Twitter accounts and opens an extra contact avenue for potential clients. It is much easier to build than many people think too &#8211; a simple call to the <a href="https://dev.twitter.com/docs" target="_blank">Twitter API</a> and you can even bypass database interaction if this is something that would make you have doubts.</p>
<p>I strongly suggest using a database though and run a &#8220;tweet loader&#8221; in the background &#8211; perhaps on a scheduled task &#8211; then display the tweets on the page to the user directly from the database. From this you could even cache the results to prevent heavy load on your own and Twitter&#8217;s servers. This not only increases load time of your web pages but you could take things a step further and implement a bad word / swear word filter and alter the accounts displayed on-the-fly.</p>
<p>The first step is to decide which Twitter accounts that you want to get the tweets for. I suggest starting with just one account and expaning how and when you wish at a later date. For the sake of this tutorial I will use just one account although adapting this for multiple accounts should be pretty obvious to you once we are done here. A simple line of code to start the procedure can be seen below where I just define the username that I want to query for. Always leave out the &#8220;@&#8221; symbol at the front of the username.</p>
<pre name="code" class="php">
&lt;?php

    // define the account username
    $account = "rossytzoltan";

?&gt;
</pre>
<p>The next step would be to set up the Twitter API integration. We will query Twitter&#8217;s REST API for statuses for this username by sending the request to a specified URL with the parameters attached. The Twitter API can be accessed at the following location:</p>
<p><code></p>
<p>http://api.twitter.com/</p>
<p></code></p>
<p>To start the integration we will define the path to the REST API and then the request that we wish to send. I have split this into two variables although you are within your rights to merge this into one. For simplicity I have split them into <em>$path</em> and <em>$request</em> as they essentially indicate two seperate things.</p>
<pre name="code" class="php">
&lt;?php

// define the path to the feed of tweets
$path = "http://api.twitter.com/1/statuses/user_timeline.xml";

// set the request for the API
$request = "?include_rts=true&#038;screen_name=".$account."&#038;count=5";

?&gt;
</pre>
<p>There are many more options that can be used in the <em>$request</em> but I have just used the ones needed which are:</p>
<ul>
<li><strong>include_rts</strong> &#8211; boolean &#8211; whether or not to display retweets in the status list.
<li><strong>screen_name</strong> &#8211; string &#8211; the Twitter account.
<li><strong>count</strong> &#8211; integer &#8211; the amount of tweets to grab.
</ul>
<p>Now that we have defined our path and request we can merge these together into one URL and query the API. As the response from the API will be in <a href="http://www.w3.org/XML/" title="XML" target="_blank">XML (eXtensible Markup Language)</a> we will use <a href="http://php.net/manual/en/book.simplexml.php" title="SimpleXML" target="_blank">SimpleXML</a> to format this response into an object ready to use. Here is how this is achieved:</p>
<pre name="code" class="php">
&lt;?php

// get the response from the API as an object
$tweet_list = simplexml_load_file($path.$request);

?&gt;
</pre>
<p>If you were to <em>print_r()</em> the <em>$tweet_list</em> variable then you will see exactly what is contained in the data. At the time of writing this article (11th January 2012) there are only three nodes in each tweet that we are going to need in order to set this up which are the actual tweet text, the time and date of which the tweet was submitted and the profile image for the user who tweeted. By using just these three items we can display our latest tweets on our website without cluttering it up. In order to get these three items though we need to loop through the tweets contained in the object then pull them out ready for use.</p>
<pre name="code" class="php">
&lt;?php

// check for Twitter posts
if ( count ( $tweet_list ) > 0 ) {

    // define the array of tweets
    $tweets = array();

    // loop through each Twitter post
    foreach ( $tweet_list as $tweet ) {

        // add the tweet to the array of tweets
        $tweets[] = array (
            'tweet'    =>    (string) $tweet->text,
            'posted'   =>    (string) $tweet->created_at,
            'image'    =>    (string) $tweet->user->profile_image_url
        );

    }

    // output how many tweets were loaded
    echo count($tweets)." were found.";

} else {

    // output a message to show no tweets found
    echo "No tweets were found.";

}

?&gt;
</pre>
<p>That&#8217;s it you have successfully queried the Twitter API, retrieved the tweets and stored them into the <em>$tweets</em> array ready to be used. If you wanted to take it a step further and display them then here is the full code with @username and link replacing plus a bit of styling thrown in for good measure.</p>
<pre name="code" class="php">
&lt;?php

	// define the account username
    $account = &quot;rossytzoltan&quot;;  

	// define the path to the feed of tweets
	$path = &quot;http://api.twitter.com/1/statuses/user_timeline.xml&quot;;  

	// set the request for the API
	$request = &quot;?include_rts=true&amp;screen_name=&quot;.$account.&quot;&amp;count=5&quot;;  

	// get the response from the API as an object
	$tweet_list = simplexml_load_file($path.$request);  

	// check for Twitter posts
	if ( count ( $tweet_list ) &gt; 0 ) {  

		// define the array of tweets
		$tweets = array();  

		// loop through each Twitter post
		foreach ( $tweet_list as $tweet ) {  

			// format links to a clickable link
			$tweet-&gt;text = preg_replace(&quot;/http:\/\/([^ ]+)/i&quot;, &quot;&lt;a href=\&quot;http://$1\&quot;&gt;http://$1&lt;/a&gt;&quot;, $tweet-&gt;text);

			// format @USERNAME into a link
			$tweet-&gt;text = preg_replace(&quot;/@([^ ]+)/&quot;, &quot;&lt;a href=\&quot;http://twitter.com/$1\&quot; target=\&quot;_blank\&quot;&gt;@$1&lt;/a&gt;&quot;, $tweet-&gt;text);

			// add the tweet to the array of tweets
			$tweets[] = array (
				'tweet'    =&gt;    (string) $tweet-&gt;text,
				'posted'   =&gt;    (string) $tweet-&gt;created_at,
				'image'    =&gt;    (string) $tweet-&gt;user-&gt;profile_image_url
			);  

		}  

		// output how many tweets were loaded
		$amount_tweets = count($tweets);  

	} else {  

		// output a message to show no tweets found
		$amount_tweets = 0;

	}  

?&gt;&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
	&lt;title&gt;Load Tweets&lt;/title&gt;
    &lt;style&gt;
		ul li{list-style:none;clear:both;overflow:auto;margin-bottom:10px;}
		ul li span.img{float:left;width:48px;height:48px;background:green;}
		ul li span.tweet{float:left;margin:5px 0 0 10px;}
		ul li span.tweet span{color:#999;}
	&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;p&gt;&lt;strong&gt;&lt;?php echo $amount_tweets; ?&gt; tweets from &lt;a href=&quot;http://twitter.com/&lt;?php echo $account; ?&gt;&quot; target=&quot;_blank&quot;&gt;@&lt;?php echo $account; ?&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
    &lt;ul&gt;
&lt;?php 

	// loop through each available tweet
	foreach ( $tweets as $tweet ) { 

?&gt;
    	&lt;li&gt;
        	&lt;span class=&quot;img&quot;&gt;&lt;img src=&quot;&lt;?php echo $tweet['image']; ?&gt;&quot; /&gt;&lt;/span&gt;
            &lt;span class=&quot;tweet&quot;&gt;&lt;?php echo $tweet['tweet']; ?&gt;&lt;br /&gt;&lt;span&gt;&lt;?php echo $tweet['posted']; ?&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;/li&gt;
        &lt;?php } ?&gt;
    &lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>If you liked this tutorial and found is useful please do tweet about it or follow me <a href="http://twitter.com/rossytzoltan" target="_blank">@rossytzoltan</a> for more of the same. There is also a comments section below in case you have any praise or comments that you would like to add.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/01/php-tutorial-twitter-statuses/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &amp; MySQL &#8211; Preventing MySQL Injection</title>
		<link>http://rosstanner.co.uk/2012/01/php-mysql-preventing-mysql-injection/</link>
		<comments>http://rosstanner.co.uk/2012/01/php-mysql-preventing-mysql-injection/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 00:40:39 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[hacker]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql injection]]></category>
		<category><![CDATA[mysql real escape string]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=307</guid>
		<description><![CDATA[<p>In this tutorial I am going to explain what MySQL injection is and how important it is to prevent this attack on your database(s). It is vital that all security measures are in place before you make your website live because the effects can be devastating especially if you store sensitive data. Lets start with [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I am going to explain what MySQL injection is and how important it is to prevent this attack on your database(s). It is vital that all security measures are in place before you make your website live because the effects can be devastating especially if you store sensitive data. Lets start with the basics and learn what MySQL injection is.</p>
<p><strong>What is MySQL injection?</strong></p>
<p>&#8220;MySQL injection is an attack technique used to exploit applications that construct SQL statements from user-supplied input.&#8221; [<a title="SQL Injection Protection" href="http://www.cyferweb.com/blog/sql-injection-protection/" target="_blank">Cyferweb.com</a>] This statement for me sums it up perfectly. It is a way of exploiting the background SQL statement by entering specific logic to a form (or other means of user input) and then sending their own commands to control your database. This could be as simple as gaining access to an admin/user area to even deleting an entire database. When sensitive data is stored it becomes even more vital to prevent this attack else you risk losing this information into the wrong hands.</p>
<p><strong>How often does this attack occur?</strong></p>
<p>It is diffult to estimate just how many websites are suffering from these attacks but it is really dependant on the level of coding. Poor coders who don&#8217;t consider the risks of MySQL injection run the risk of losing their entire database or more importantly &#8211; a client&#8217;s database. PHP developers that put the effort it to prevent such attacks are those considered much more advanced and in the long run saving lots of important data.</p>
<p><strong>Can you show me an example of MySQL injection?</strong></p>
<p>MySQL injection is really very easy and anyone can do it. Take the following example: a user supplies a username and password to enter the administration section of a website. A poorly written login script will query the database directly for either the username, password or both without stripping/escaping each string first. Check out the code below:</p>
<pre name="code" class="php">
&lt;?php
$query = mysql_query("SELECT id FROM users WHERE username = '".$username."' AND password = '".$password."'");
?&gt;
</pre>
<p>As you can see the database is queried for a record matching the username AND the password. Now, if I was to enter my password as <strong>&#8216; OR 1=1&#8242;</strong> then this would cause the query to match 1 to 1, which is of course true &#8211; 1 does equal 1. This will result in a positive login and the hacker gaining access to a restricted area of the website. This is a very simple example of how MySQL injection can occur.</p>
<p><strong>How do I prevent MySQL injection?</strong></p>
<p>All you need to do to prevent these attacks is to ensure that you escape each item being passed into the query. Normally you wouldn&#8217;t query the users table for both the username and password but for the sake of this tutorial I will keep the query the same. The best way of going around it would be to query for the username (escaped) whilst returning the password from the table, then matching the string passed through the form with the password that is returned. That way you can match hash/salts for encrypted passwords.</p>
<p>I normally always use <strong>mysql_real_escape_string()</strong> to escape my user-inputted data because it escapes any special characters (such as <strong>&#8216; </strong>and <strong>&#8220;</strong> which are the prime cause of MySQL injection). Therefore your new query would look like this:</p>
<pre name="code" class="php">
&lt;?php
$query = mysql_query("SELECT id FROM users WHERE username = '".mysql_real_escape_string($username)."' AND password = '".mysql_real_escape_string($password)."'");
?&gt;
</pre>
<p>The password is now escaped meaning that if that same injection string was to be passed through the form, it would actually look for a password matching that instead of manipulating the query. The hacker would have no way (using MySQL injection anyway) of altering or even deleting your database.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/01/php-mysql-preventing-mysql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial &#8211; Connect to multiple databases with PHP and MySQL</title>
		<link>http://rosstanner.co.uk/2012/01/php-tutorial-connect-multiple-databases-php-mysql/</link>
		<comments>http://rosstanner.co.uk/2012/01/php-tutorial-connect-multiple-databases-php-mysql/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 20:39:30 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[multiple databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql connect]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=302</guid>
		<description><![CDATA[<p>A nice and simple PHP tutorial today where I will show you how to connect to multiple MySQL databases at once using PHP. I&#8217;m sure when you first considered the option of multiple connections you thought it wasn&#8217;t possible, difficult to do or there is a long winded way of doing it (such as disconnecting [...]]]></description>
			<content:encoded><![CDATA[<p>A nice and simple PHP tutorial today where I will show you how to connect to multiple MySQL databases at once using PHP. I&#8217;m sure when you first considered the option of multiple connections you thought it wasn&#8217;t possible, difficult to do or there is a long winded way of doing it (such as disconnecting and re-connecting each time you want to make a query). This is untrue. All that you need to do is define a new connection and save it as a seperate resource. So, a simple one-database connection would look like this:</p>
<pre name="code" class="php">&lt;?php

    // connect to the database server
    $conn = mysql_connect("HOST", "USERNAME", "PASSWORD");

    // select the database to connect to
    mysql_select_db("DATABASE", $conn);

    // query the database
    $query = mysql_query("SELECT * FROM users", $conn);

    // close the database connection
    mysql_close($conn);

?&gt;</pre>
<p>Now if you were to have a second connection, instead of disconnecting from <strong>$conn</strong> and re-connecting as a seperate connection, you can keep the first one alive and create a second. Just like follows:</p>
<pre name="code" class="php">&lt;?php

    // connect to the database server
    $conn = mysql_connect("HOST", "USERNAME", "PASSWORD");

    // select the database to connect to
    mysql_select_db("DATABASE", $conn);

    // connect to the second database server
    $conn2 = mysql_connect("HOST", "USERNAME", "PASSWORD");

    // select the database to connect to
    mysql_select_db("DATABASE", $conn2);

    // query the first database
    $query = mysql_query("SELECT * FROM users", $conn);

    // query the second database
    $query = mysql_query("SELECT * FROM articles", $conn2);

    // close the database connections
    mysql_close($conn);
    mysql_close($conn2);

?&gt;</pre>
<p>As you can see I have two open connections and I am interacting with both databases. At the end I simply close both connections. It is as simple as that. Any questions please don&#8217;t hesitate to ask in the comments section below. Alternatively ping me a message or a tweet on Twitter &#8211; <a href="http://twitter.com/rossytzoltan" target="_blank">@rossytzoltan</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2012/01/php-tutorial-connect-multiple-databases-php-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial &#8211; Download Your Online Fifa 12 Results [PS3]</title>
		<link>http://rosstanner.co.uk/2011/12/download-your-online-fifa-12-results-playstation-3-php-tutorial/</link>
		<comments>http://rosstanner.co.uk/2011/12/download-your-online-fifa-12-results-playstation-3-php-tutorial/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 23:25:18 +0000</pubDate>
		<dc:creator>Ross Tanner</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[download fifa 12 results]]></category>
		<category><![CDATA[ea]]></category>
		<category><![CDATA[ea sports]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[fifa]]></category>
		<category><![CDATA[fifa 12]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[playstation]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://rosstanner.co.uk/?p=273</guid>
		<description><![CDATA[<p>Welcome to my newest tutorial &#8211; using PHP to get your latest online Fifa results which you could post on your social networking sites, put on your website (like I have at the top of my sidebar) or even create online friendship leader boards and such like.</p> <p>So, how did I achieve this? I can [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to my newest tutorial &#8211; using PHP to get your latest online Fifa results which you could post on your social networking sites, put on your website (like I have at the top of my sidebar) or even create online friendship leader boards and such like.</p>
<p>So, how did I achieve this? I can tell you first off that it requires no direct interaction with the EA or PS3 servers, but uses something much more simple.</p>
<p>Before we do anything you first need to check that the relevant PHP modules are installed on your server. If you use XAMPP as a local testing server then the most recent version (1.7.7 at time of writing) comes with everyone installed as default. The PHP module that you need is IMAP (http://www.php.net/manual/en/book.imap.php). You can check your installation details by loading up a PHP file containing the function <strong>phpinfo();</strong> like so:</p>
<pre name="code" class="php">
&lt;?php phpinfo(); ?&gt;
</pre>
<p></p>
<p>If the module is indeed installed then you should see something somewhat similar to this:</p>
<p><a href="http://rosstanner.co.uk/wp-content/uploads/2011/12/imap.jpg"><img src="http://rosstanner.co.uk/wp-content/uploads/2011/12/imap-300x60.jpg" alt="" title="IMAP PHP" width="300" height="60" class="alignleft size-medium wp-image-275" /></a></p>
<p>If you don&#8217;t see the IMAP module then you don&#8217;t have it installed. Read through the <a href="http://www.php.net/manual/en/imap.installation.php" target="_blank">installation guide on the PHP manual website</a> for instructions.</p>
<p>The next step is to go into your online settings on your Fifa 12 game. Unfortunately I only have a Playstation 3 since my Xbox had the red ring of death twice so I can only give instructions for this console. I&#8217;m sure the Xbox 360 version is fairly similar though. On the PS3 if you boot up the game then go to <strong>Online Modes</strong> > <strong>My Fifa 12 Online</strong> > <strong>Online Settings</strong> > <strong>Match Reports</strong> then ensure that <strong>Forward End-of-Game Stats</strong> is set to <strong>Yes</strong>. You will now receive match reports by email after every online game you play. We will use PHP to read your emails and then extract the match statistics ready to use. Cool, right?</p>
<p>Now comes the fun part, the development side of things. Open up a blank PHP file in the code editor of your choice. Personally I prefer <a href="http://www.adobe.com/products/dreamweaver.html" title="Adobe Dreamweaver" target="_blank">Adobe Dreamweaver</a> but that&#8217;s because I learnt using it and it&#8217;s just been perfect for my needs. Call this file something like <strong>read_mail.php</strong> because this is the script that will do all the leg-work.</p>
<p>It really depends what you want to do with the data which dictates how the script will be laid out. If we assume that the data will be inserted into a database then we can use it freely and at any time we like. With this in mind here is an example table structure:</p>
<pre name="code" class="sql">
CREATE TABLE IF NOT EXISTS `fifa` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email_id` varchar(50) NOT NULL,
  `timestamp` int(10) NOT NULL,
  `venue` enum('Home','Away') NOT NULL,
  `opponent` varchar(30) NOT NULL,
  `result` enum('W','D','L') NOT NULL,
  `home_team` varchar(40) NOT NULL,
  `away_team` varchar(40) NOT NULL,
  `home_score` smallint(2) NOT NULL,
  `away_score` smallint(2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
</pre>
<p>The first line would of course then be the database connection. Anyone who regularly develops using this scripting language will know exactly how to do this and will know the code inside out so I&#8217;m not going into considerable detail but here is the basic way of doing it:</p>
<pre name="code" class="php">
&lt;?php

// FIFA settings
$fifa_username = "YOUR_PSN_HANDLE";

// MySQL database settings - change to suit your settings
$database = array (
"host" => "DATABASE_HOST",
"user" => "DATABASE_USERNAME",
"pass" => "DATABASE_PASSWORD",
"database" => "DATABASE_NAME"
);

// email account settings - change to suit your details
$email = array (
"host" => "EMAIL_HOST",
"user" => "EMAIL_ADDRESS",
"pass" => "EMAIL_PASSWORD",
);

// connect to the MySQL server using the settings provided
$db = mysql_connect ( $database['host'], $database['user'], $database['pass'] );

// select the database to connect to
mysql_select_db ( $database['database'] );

// array of club words (for later matching strings to club names) - add clubs as required
$club_words = array ( "Arsenal", "Chelsea", "Manchester", "United", "City", "Liverpool", "Tottenham", "PSG", "Olympique", "Lyon", "Marseille", "Milan", "AC", "Fiorentina", "Juventus", "Lazio", "Roma", "Ajax", "PSV", "Porto", "SL", "Benfica", "Celtic", "Rangers", "Real", "Madrid", "FC", "CF", "Barcelona", "Valencia", "Inter", "Bayern", "Munich", "Munchen", "München", "Argentina", "Spain", "England", "France", "Holland", "Netherlands", "Germany", "Italy", "Brazil", "Uruguay", "Portugal" );

?&gt;
</pre>
<p>
The code above simply sets the settings which we will use in the script then connects to the database. You will need to change the bits in capital letters to suit the settings of your database and email account. Again, it is very basic and doesn&#8217;t contain any error checking or connection errors. I&#8217;m not going into huge detail i&#8217;m just aiming to show you how it&#8217;s done. You will also see an array of club names. This is used because later on we split the body of the email by each word and some clubs contain two words, such as Real Madrid, FC Barcelona, Manchester United, etc.</p>
<p>The next step is to connect to our email account using the email settings provided into the array. We will also sort the emails that are found in the inbox and count them up ready for use. We do this in the following way:</p>
<pre name="code" class="php">
&lt;?php

// connect to the email account using the settings provided
$mbox = imap_open ( "{" . $email['host'] . ":143/novalidate-cert}INBOX", $email['user'], $email['pass']);

// sort the inbox list of emails by retrieval date - reversed
$sorted_mbox = imap_sort ( $mbox, SORTDATE, 1 );

// get the total amount of email messages in the inbox
$totalrows = imap_num_msg ( $mbox );

?&gt;
</pre>
<p></p>
<p>OK, so we have managed to connect to our database and our email account. Let&#8217;s not forgot to close those two connections at the end of the script otherwise we could potentially end up with lots of open connections waiting to be used. Not only will this form an eventually large queue, it could cause slowness, downtime and even affect other websites if using a shared server. Let&#8217;s not do that if we can help it. To close the connections stick the following to lines <strong>at the end of the script</strong>, bearing in mind we are about to add more code before this.</p>
<pre name="code" class="php">
&lt;?php

// close the email connection
imap_close ( $mbox );

// close the database connection
mysql_close ( $db );

?&gt;
</pre>
<p></p>
<p>The next lot of code is in a big block because we will begin looping the email messages in our inbox. We will use a simple <em>for</em> loop to do this for each item in the inbox. I have commented each line to walk you through the process but be aware this bit is quite complex due to the pattern matching and string replacing. The basics of the code below is:</p>
<ol>
<li>Loop through each email message in the inbox folder.</li>
<li>Get the email headers so that we have an ID, correct email to open (we only want the EA ones) and also a timestamp of when the email was received.</li>
<li>Check that the message contains an ID.</li>
<li>Get that ID found and save it into a variable (<em>$id</em>).</li>
<li>Pattern match against the subject to see if it contains &#8220;now see the stats!&#8221; &#8211; the generic EA match report subject.</li>
<li>Get the body content, strip tags and split it down into an easy, manageable block of text.</li>
<li>Split the list into an array of words from the string.</li>
<li>Get the timestamp that the email was received on.</li>
<li>Check whether the game was played at home or away.</li>
<li>Get the home team&#8217;s name and the opponent&#8217;s username.</li>
<li>Get the away team&#8217;s name.</li>
<li>Find out the final score of the match.</li>
<li>Query if this email record already exists in the database.</li>
<li>If it doesn&#8217;t, insert the record.</li>
</ol>
<pre name="code" class="php">
&lt;?php

// loop through each email message
for ( $i = 0; $i <= $totalrows; $i++ ) {

    // get the message headers
    $headers = @imap_fetchheader ( $mbox, $sorted_mbox[$i] );

    // check that the email message contains an ID (for unique matching)
    if ( preg_match ( "/id ([A-z0-9\-]+)/i", $headers, $matches ) ) {

        // retrieve the id that was matched in the expression
        $id = $matches[1];

	// search for an email sent with the subject required (from EA)
        if ( preg_match ( '/Subject: (.*)/m', $headers, $matches ) &#038;&#038; preg_match ( '/now see the stats!/', $matches[1] ) ) {

            // get the body of the email message and strip any HTML tags to leave us with plain text
            $body = strip_tags(imap_body ( $mbox, $sorted_mbox[$i] ));

            // split the string so that we only have a block that we can work on
            $body = substr ( $body, stripos ( $body, "H=" ), stripos ( $body, "&copy;" ) );

            // remove any new line characters
            $body = str_replace ( "\n", "", $body );

            // remove any spaces with a pipe symbol so that we can explode the string by each seperate word
            $body = preg_replace ( "/\s+/", "|", $body );

            // remove the funny characters in the string
            $body = str_replace ( "=|", "", str_replace ( "=20", "", $body ) );

            // get an array of words by exploding by the pipe - also remove blank array elements
            $items = array_filter ( explode ( "|", $body ) );

            // set the array for stats collection
            $stats = array();

            /* BEGIN DATA COLLECTION */

            // pattern match for a timestamp (when the email was received)
            preg_match ( "/t=([0-9]+)/", $headers, $matches );
	    $timestamp = $matches[1];

            // get the venue (home or away) by searching for the whereabouts of the username
            if ( $items[0] == "HOME" &#038;&#038; ( $items[2] == $fifa_username || $items[3] == $fifa_username ) ) { $stats['venue'] = "Home"; }
            else if ( ( $items[6] == "AWAY" || $items[7] == "AWAY" ) &#038;&#038; ( $items[7] == $fifa_username || $items[8] == $fifa_username || $items[9] == $fifa_username || $items[10] == $fifa_username ) ) { $stats['venue'] = "Away";	}

            // get the opponent played against
            $stats['home']['team'] = $items[1];

            // if the venue is away - get the opponent from the home side of the stats
            if ( $stats['venue'] == 'Away' ) { $stats['opponent'] = $items[2]; }

            // check if the word following the club name is also a club word (for clubs with 2 words, like FC Barcelona or Real Madrid)
            if ( in_array ( $items[2], $club_words ) ) {

                // append the second word to the club name
                $stats['home']['team'] .= ' '.$items[2];

                // check the venue is away - set the opponent as the next array element because the club name is multiple words
                if ( $stats['venue'] == 'Away' ) { $stats['opponent'] = $items[3]; }

	    }

            // loop through each array element - getting the key and the value pair
            foreach ( $items as $key => $item ) {

                // check if the current item in the loop is the away team marker
                if ( $item == 'AWAY' ) {

                    // the name of the away team must be the next element after the away team marker
                    $stats['away']['team'] = $items[($key+1)];

                    // check for the location of the venue - the opponent must be 2 (or possibly 3) items further on because the team name was after the marker
                    if ( $stats['venue'] == 'Home' ) { $stats['opponent'] = $items[($key+2)]; }

                    // check if the element following on from the club name is also part of the name (like Manchester UNITED or Inter MILAN)
                    if ( in_array ( $items[($key+2)], $club_words ) ) {

                        // if it was also part of the name, append this onto the end of the club name
                        $stats['away']['team'] .= ' '.$items[($key+2)];

                        // check the location of the venue for the opponent's username
                        if ( $stats['venue'] == 'Home' ) { $stats['opponent'] = $items[($key+3)]; }

                    }

                }

                // look for the score marker (the hyphen between 1-0, 1-2, 6-0, etc)
		if ( $item == '-' ) {

                    // the home team's score must be to the left of this marker - the away team's to the right
                    $stats['home']['score'] = (int) trim($items[($key-1)]);
                    $stats['away']['score'] = (int) trim($items[($key+1)]);

		}

                // define the result based on the score line
                if ( ( $stats['venue'] == 'Home' &#038;&#038; ( $stats['home']['score'] > $stats['away']['score'] ) ) || ( $stats['venue'] == 'Away' &#038;&#038; ( $stats['home']['score'] < $stats['away']['score'] ) ) ) { $stats['result'] = 'W'; } 

                // check for a draw?
                else if ($stats['home']['score'] == $stats['away']['score'] ) {
                    $stats['result'] = 'D';
                } 

                // else the result must have been a loss
                else { $stats['result'] = 'L'; }

	    }

            /* END DATA COLLECTION */

            /* BEGIN DATABASE INTERACTION */

            // query for this ID in the FIFA database table
            $query = mysql_query ( "SELECT id FROM fifa WHERE email_id = '".$id."' LIMIT 1", $db );

            // check if a record already exists in this table
            if ( mysql_num_rows ( $query ) < 1 ) {

                // insert the database record
                mysql_query ( "INSERT INTO fifa ( email_id, timestamp, venue, opponent, result, home_team, away_team, home_score, away_score ) VALUES ( '".$id."', ".$timestamp.", '".$stats['venue']."', '".$stats['opponent']."', '".$stats['result']."', '".$stats['home']['team']."', '".$stats['away']['team']."', '".$stats['home']['score']."', '".$stats['away']['score']."' )", $db );

            }

            /* END DATABASE INTERACTION */

        }

    }

} // end loop
?&gt;
</pre>
<p></p>
<p>The code above can be quite confusing and difficult to follow which is why I have split it down into steps above. The full, final script can be seen below:</p>
<pre name="code" class="php">
&lt;?php

// FIFA settings
$fifa_username = "YOUR_PSN_HANDLE";

// MySQL database settings - change to suit your settings
$database = array (
"host" => "DATABASE_HOST",
"user" => "DATABASE_USERNAME",
"pass" => "DATABASE_PASSWORD",
"database" => "DATABASE_NAME"
);

// email account settings - change to suit your details
$email = array (
"host" => "EMAIL_HOST",
"user" => "EMAIL_ADDRESS",
"pass" => "EMAIL_PASSWORD",
);

// connect to the MySQL server using the settings provided
$db = mysql_connect ( $database['host'], $database['user'], $database['pass'] );

// select the database to connect to
mysql_select_db ( $database['database'] );

// array of club words (for later matching strings to club names) - add clubs as required
$club_words = array ( "Arsenal", "Chelsea", "Manchester", "United", "City", "Liverpool", "Tottenham", "PSG", "Olympique", "Lyon", "Marseille", "Milan", "AC", "Fiorentina", "Juventus", "Lazio", "Roma", "Ajax", "PSV", "Porto", "SL", "Benfica", "Celtic", "Rangers", "Real", "Madrid", "FC", "CF", "Barcelona", "Valencia", "Inter", "Bayern", "Munich", "Munchen", "München", "Argentina", "Spain", "England", "France", "Holland", "Netherlands", "Germany", "Italy", "Brazil", "Uruguay", "Portugal" );

// connect to the email account using the settings provided
$mbox = imap_open ( "{" . $email['host'] . ":143/novalidate-cert}INBOX", $email['user'], $email['pass']);

// sort the inbox list of emails by retrieval date - reversed
$sorted_mbox = imap_sort ( $mbox, SORTDATE, 1 );

// get the total amount of email messages in the inbox
$totalrows = imap_num_msg ( $mbox );

// loop through each email message
for ( $i = 0; $i <= $totalrows; $i++ ) {

    // get the message headers
    $headers = @imap_fetchheader ( $mbox, $sorted_mbox[$i] );

    // check that the email message contains an ID (for unique matching)
    if ( preg_match ( "/id ([A-z0-9\-]+)/i", $headers, $matches ) ) {

        // retrieve the id that was matched in the expression
        $id = $matches[1];

	// search for an email sent with the subject required (from EA)
        if ( preg_match ( '/Subject: (.*)/m', $headers, $matches ) &#038;&#038; preg_match ( '/now see the stats!/', $matches[1] ) ) {

            // get the body of the email message and strip any HTML tags to leave us with plain text
            $body = strip_tags(imap_body ( $mbox, $sorted_mbox[$i] ));

            // split the string so that we only have a block that we can work on
            $body = substr ( $body, stripos ( $body, "H=" ), stripos ( $body, "&copy;" ) );

            // remove any new line characters
            $body = str_replace ( "\n", "", $body );

            // remove any spaces with a pipe symbol so that we can explode the string by each seperate word
            $body = preg_replace ( "/\s+/", "|", $body );

            // remove the funny characters in the string
            $body = str_replace ( "=|", "", str_replace ( "=20", "", $body ) );

            // get an array of words by exploding by the pipe - also remove blank array elements
            $items = array_filter ( explode ( "|", $body ) );

            // set the array for stats collection
            $stats = array();

            /* BEGIN DATA COLLECTION */

            // pattern match for a timestamp (when the email was received)
            preg_match ( "/t=([0-9]+)/", $headers, $matches );
	    $timestamp = $matches[1];

            // get the venue (home or away) by searching for the whereabouts of the username
            if ( $items[0] == "HOME" &#038;&#038; ( $items[2] == $fifa_username || $items[3] == $fifa_username ) ) { $stats['venue'] = "Home"; }
            else if ( ( $items[6] == "AWAY" || $items[7] == "AWAY" ) &#038;&#038; ( $items[7] == $fifa_username || $items[8] == $fifa_username || $items[9] == $fifa_username || $items[10] == $fifa_username ) ) { $stats['venue'] = "Away";	}

            // get the opponent played against
            $stats['home']['team'] = $items[1];

            // if the venue is away - get the opponent from the home side of the stats
            if ( $stats['venue'] == 'Away' ) { $stats['opponent'] = $items[2]; }

            // check if the word following the club name is also a club word (for clubs with 2 words, like FC Barcelona or Real Madrid)
            if ( in_array ( $items[2], $club_words ) ) {

                // append the second word to the club name
                $stats['home']['team'] .= ' '.$items[2];

                // check the venue is away - set the opponent as the next array element because the club name is multiple words
                if ( $stats['venue'] == 'Away' ) { $stats['opponent'] = $items[3]; }

	    }

            // loop through each array element - getting the key and the value pair
            foreach ( $items as $key => $item ) {

                // check if the current item in the loop is the away team marker
                if ( $item == 'AWAY' ) {

                    // the name of the away team must be the next element after the away team marker
                    $stats['away']['team'] = $items[($key+1)];

                    // check for the location of the venue - the opponent must be 2 (or possibly 3) items further on because the team name was after the marker
                    if ( $stats['venue'] == 'Home' ) { $stats['opponent'] = $items[($key+2)]; }

                    // check if the element following on from the club name is also part of the name (like Manchester UNITED or Inter MILAN)
                    if ( in_array ( $items[($key+2)], $club_words ) ) {

                        // if it was also part of the name, append this onto the end of the club name
                        $stats['away']['team'] .= ' '.$items[($key+2)];

                        // check the location of the venue for the opponent's username
                        if ( $stats['venue'] == 'Home' ) { $stats['opponent'] = $items[($key+3)]; }

                    }

                }

                // look for the score marker (the hyphen between 1-0, 1-2, 6-0, etc)
		if ( $item == '-' ) {

                    // the home team's score must be to the left of this marker - the away team's to the right
                    $stats['home']['score'] = (int) trim($items[($key-1)]);
                    $stats['away']['score'] = (int) trim($items[($key+1)]);

		}

                // define the result based on the score line
                if ( ( $stats['venue'] == 'Home' &#038;&#038; ( $stats['home']['score'] > $stats['away']['score'] ) ) || ( $stats['venue'] == 'Away' &#038;&#038; ( $stats['home']['score'] < $stats['away']['score'] ) ) ) { $stats['result'] = 'W'; } 

                // check for a draw?
                else if ($stats['home']['score'] == $stats['away']['score'] ) {
                    $stats['result'] = 'D';
                } 

                // else the result must have been a loss
                else { $stats['result'] = 'L'; }

	    }

            /* END DATA COLLECTION */

            /* BEGIN DATABASE INTERACTION */

            // query for this ID in the FIFA database table
            $query = mysql_query ( "SELECT id FROM fifa WHERE email_id = '".$id."' LIMIT 1", $db );

            // check if a record already exists in this table
            if ( mysql_num_rows ( $query ) < 1 ) {

                // insert the database record
                mysql_query ( "INSERT INTO fifa ( email_id, timestamp, venue, opponent, result, home_team, away_team, home_score, away_score ) VALUES ( '".$id."', ".$timestamp.", '".$stats['venue']."', '".$stats['opponent']."', '".$stats['result']."', '".$stats['home']['team']."', '".$stats['away']['team']."', '".$stats['home']['score']."', '".$stats['away']['score']."' )", $db );

            }

            /* END DATABASE INTERACTION */

        }

    }

} // end loop

// close the email connection
imap_close ( $mbox );

// close the database connection
mysql_close ( $db );

?&gt;
</pre>
<p></p>
<p>Believe it or not this is actually only pulling the basic information such as home team, away team, venue, opponent, the score and the result. The script I use is even more complex and pulls the possession percentages for each team, passing accuracy, tackling, shots (on and off target), cards (reds and yellows) and lots more.</p>
<p>You can also <a href="http://rosstanner.co.uk/wp-content/uploads/2011/12/fifa.zip" target="_blanK">download the final code here</a>. I hope this was readable enough and any problems, questions or nags you have can be posted below in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://rosstanner.co.uk/2011/12/download-your-online-fifa-12-results-playstation-3-php-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

