<?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>Mike Griffiths &#187; php</title>
	<atom:link href="http://www.mike-griffiths.co.uk/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mike-griffiths.co.uk</link>
	<description>Blog</description>
	<lastBuildDate>Wed, 11 Aug 2010 11:26:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CodeIgniter &#8211; The best framework for the job?</title>
		<link>http://www.mike-griffiths.co.uk/codeigniter-the-best-framework-for-the-job/</link>
		<comments>http://www.mike-griffiths.co.uk/codeigniter-the-best-framework-for-the-job/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 13:45:19 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Findings]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.mike-griffiths.co.uk/?p=176</guid>
		<description><![CDATA[Most web developers have their own code base that they refer back to on a regular basis. Many have even developed their own simple platforms that do a lot of the leg work for them, that they know inside out and can easily deploy on a new project.
More recently though, at least in the last [...]]]></description>
			<content:encoded><![CDATA[<p>Most web developers have their own code base that they refer back to on a regular basis. Many have even developed their own simple platforms that do a lot of the leg work for them, that they know inside out and can easily deploy on a new project.</p>
<p>More recently though, at least in the last 4-5 years, frameworks have been popping up left right and centre. From CakePHP, which is generally considered to be a little unstable, to the super-reliable ZendFramework, built by Zend &#8211; the PHP company.</p>
<p>Zend and Cake are not he only frameworks though. After trying a lot, I find my personal favourite to be <a href="http://www.codeigniter.com">CodeIgniter</a>, which is built by EllisLabs.</p>
<p>CodeIgniter comes with libraries and helpers that can be activated at any point within the framework. These helpers try and simplify many tedious tasks involved with making web applications. Things like form validation is a breeze, and the functions used are much more powerful than something that can be drummed up quickly in any normal PHP app. Image manipulation is made easy, and emailing through PHP can be done well without needing to load in the bloated PEAR, which the documentation recommends.</p>
<p>CodeIgniter uses standard MVC (Model > View > Controller) to create it&#8217;s systems. Although at first glance this can seem a little silly and over-thought, but it makes life a lot easier for everyone involved. The MVC structure is standardised, reliable and fast, and every developer should follow suit with it very easily.</p>
<p>CodeIgniter also makes debugging applications very easy. The built-in profiler shows all of the POST, and GET data, aswell as all database queries. I used a customised version of the profiler that I tweaked to also show SESSION data.</p>
<p>When working with lots of small, simple queries CodeIgniter also makes life easy with active records, their database library. It allows queries to be written with a fraction of the amount of code. Let&#8217;s say we want to pull off everything from a table, simple: db->get(&#8217;table&#8217;) &#8211; no need to write a full query to do it. Active records do support large queries with unlimited amounts of JOINs, but my personal preference is to compile these myself and throw them into a normal query using the DB library&#8217;s db->query() method &#8211; probably because I&#8217;m used to the structure of the queries and the syntax so I can spot errors more easily. If you&#8217;re not hot on SQL though, you&#8217;ll probably benefit massively.</p>
<p>My personal framework recommendation is definitely CodeIgniter, but make sure you check out all of the others available too. CodeIgniter has a massive community that helps solve any problem you may have, the community includes forums and live chat rooms, which the EllisLabs developers often frequent. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mike-griffiths.co.uk/codeigniter-the-best-framework-for-the-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEO Friendly PHP Twitter Script</title>
		<link>http://www.mike-griffiths.co.uk/seo-friendly-php-twitter-script/</link>
		<comments>http://www.mike-griffiths.co.uk/seo-friendly-php-twitter-script/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 00:34:15 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.mike-griffiths.co.uk/?p=148</guid>
		<description><![CDATA[There are loads of scripts out there for pulling in your Twitter posts.  A lot, if not most of them, base themselves heavily on JavaScript.  This is bad for 3 reasons:

People with JS disabled can&#8217;t read them
It&#8217;s bad for your website&#8217;s search engine rank (SEO) as the search bots can&#8217;t read them
It slows [...]]]></description>
			<content:encoded><![CDATA[<p>There are loads of scripts out there for pulling in your <a href="http://twitter.com/mikemike86">Twitter</a> posts.  A lot, if not most of them, base themselves heavily on JavaScript.  This is bad for 3 reasons:</p>
<ol>
<li>People with JS disabled can&#8217;t read them</li>
<li>It&#8217;s bad for your website&#8217;s search engine rank (SEO) as the search bots can&#8217;t read them</li>
<li>It slows user&#8217;s browsers down (if only slightly)</li>
</ol>
<p>I have written a very simple PHP script that pulls in your Twitter posts, and outputs them in an unordered list.  Feel free to use however you like:</p>
<pre lang="php">
&lt;?php
// Your Twitter username
$username = 'mikemike86';
$rssUrl = "http://twitter.com/statuses/user_timeline/$username.rss";
$rss = @file_get_contents($rssUrl);

if($rss){
	$xml = @simplexml_load_string($rss);
		if($xml !== false){
			$var=true;
			foreach($xml->channel->item as $tweet){
				//echo $tweet->pubDate."\n";
				echo '<a href="'.$tweet->link.'" title="Go to SEO tweet">'.substr($tweet->description,(strlen($username)+2))."</a>\n\n";

				if($var){
					break;
				}
			}
		} else {
			echo "Error: RSS file not valid!";
		}
	} else {
		echo "Error: RSS file not found. Username invalid or requires authentication";
	}
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mike-griffiths.co.uk/seo-friendly-php-twitter-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP json_encode Alternative</title>
		<link>http://www.mike-griffiths.co.uk/php-json_encode-alternative/</link>
		<comments>http://www.mike-griffiths.co.uk/php-json_encode-alternative/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 00:19:30 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[json_encode]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.mike-griffiths.co.uk/?p=144</guid>
		<description><![CDATA[The amount of times I&#8217;ve been working on a project and the environment hasn&#8217;t had the useful json_encode function installed due to PHP being < version 5.2 is quite worrying.  So, I decided to write my own replacement.  How very decent of me.  You can use it as you will.  I [...]]]></description>
			<content:encoded><![CDATA[<p>The amount of times I&#8217;ve been working on a project and the environment hasn&#8217;t had the useful <em>json_encode</em> function installed due to PHP being < version 5.2 is quite worrying.  So, I decided to write my own replacement.  How very decent of me.  You can use it as you will.  I wrote this a long time ago, but I've noticed it's somehow wormed its way onto the php.net site under someone elses name, and someone else seems to be taking credit for it.  Oh well...</p>
<pre lang="php">&lt;?php
if (!function_exists(&#8217;json_encode&#8217;))
{
	function json_encode($a=false)
	{
		// Some basic debugging to ensure we have something returned
		if (is_null($a)) return &#8216;null&#8217;;
		if ($a === false) return &#8216;false&#8217;;
		if ($a === true) return &#8216;true&#8217;;
		if (is_scalar($a))
		{
			if (is_float($a))
			{
				// Always use &#8220;.&#8221; for floats.
				return floatval(str_replace(&#8221;,&#8221;, &#8220;.&#8221;, strval($a)));
			}

			if (is_string($a))
			{
				static $jsonReplaces = array(array(&#8221;\\&#8221;, &#8220;/&#8221;, &#8220;\n&#8221;, &#8220;\t&#8221;, &#8220;\r&#8221;, &#8220;\b&#8221;, &#8220;\f&#8221;, &#8216;&#8221;&#8216;), array(&#8217;\\\\&#8217;, &#8216;\\/&#8217;, &#8216;\\n&#8217;, &#8216;\\t&#8217;, &#8216;\\r&#8217;, &#8216;\\b&#8217;, &#8216;\\f&#8217;, &#8216;\&#8221;&#8216;));
				return &#8216;&#8221;&#8216; . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . &#8216;&#8221;&#8216;;
			}
			else
				return $a;
		}
		$isList = true;
		for ($i = 0, reset($a); $i {
			if (key($a) !== $i)
			{
				$isList = false;
				break;
			}
		}
		$result = array();
		if ($isList)
		{
			foreach ($a as $v) $result[] = json_encode($v);
			return &#8216;[' . join(',', $result) . ']&#8216;;
		}
		else
		{
			foreach ($a as $k => $v) $result[] = json_encode($k).&#8217;:&#8217;.json_encode($v);
			return &#8216;{&#8217; . join(&#8217;,', $result) . &#8216;}&#8217;;
		}
	}
}
?&gt; </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mike-griffiths.co.uk/php-json_encode-alternative/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>An Interesting Problem</title>
		<link>http://www.mike-griffiths.co.uk/an-interesting-problem/</link>
		<comments>http://www.mike-griffiths.co.uk/an-interesting-problem/#comments</comments>
		<pubDate>Thu, 07 May 2009 17:45:29 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.mike-griffiths.co.uk/?p=39</guid>
		<description><![CDATA[Myself and another developer have begun work on a new project that will integrate into Twitter.  It&#8217;s quite a novel idea and I&#8217;m very surprised it hasn&#8217;t been done already, but there will be more on that once it&#8217;s ready for public use.
But enough on that, this post is about a problem we came [...]]]></description>
			<content:encoded><![CDATA[<p>Myself and another developer have begun work on a new project that will integrate into <a href="http://twitter.com" target="_blank">Twitter</a>.  It&#8217;s quite a novel idea and I&#8217;m very surprised it hasn&#8217;t been done already, but there will be more on that once it&#8217;s ready for public use.</p>
<p>But enough on that, this post is about a problem we came across when building it.  Basically we wanted to create a block of 100 cells, each numbered, but the rows are to go in a zigzag fashion, starting in the bottom left at 0 and ending in top left with 100, and obviously this isn&#8217;t to be done manually.  Find an example below:</p>
<pre>100 99 98 97 96 95 94 93 92 91
81 82 83 84 85 86 87 88 89 90
80 79 78 77 76 75 74 73 72 71
61 62 63 64 65 66 67 68 69 70
60 59 58 57 56 55 54 53 52 51
41 42 43 44 45 46 47 48 49 50
40 39 38 37 36 35 34 33 32 31
21 22 23 24 25 26 27 28 29 30
20 19 18 17 16 15 14 13 12 11
1 2 3 4 5 6 7 8 9 10</pre>
<p>Here is what I came up with (PHP):</p>
<pre lang="php">
$i=99;
for ($x = 100; $x > 0; $x--)
{
        echo $x . ' ';
        if($i%10==0) {
                // Display new line
                echo "\n";
                // Loop through 10
                for($y = ($x-10); $y < ($x); $y++){
                        echo $y . ' ';
                        if($y%10==0) echo "\n";
                }
                // Add ten onto $x and $i
                $x = $x-10;
                $i = $i-10;
        }
        $i--;
}
</pre>
<p>Although this is relatively efficient, I'm sure there must be a better way of doing it.  Any ideas?  Leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mike-griffiths.co.uk/an-interesting-problem/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
