<?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>Rob Searles &#187; PHP</title>
	<atom:link href="http://www.robsearles.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.robsearles.com</link>
	<description>Musing on the business of and development for "The Web"</description>
	<lastBuildDate>Mon, 31 May 2010 15:44:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing PHP5.3 on Ubuntu Karmic</title>
		<link>http://www.robsearles.com/2010/03/17/installing-php5-3-on-ubuntu-karmic/</link>
		<comments>http://www.robsearles.com/2010/03/17/installing-php5-3-on-ubuntu-karmic/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 23:02:53 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=275</guid>
		<description><![CDATA[Following my previous post about installing PHP5.3 on Jaunty, I have had a few requests about installing it on Karmic. I&#8217;ve never used Karmic before so I thought it would be a fun excuse to have a poke about whilst also keeping my blog (sort of) up-to-date.
After freshly installing Karmic (the desktop version looks very [...]]]></description>
			<content:encoded><![CDATA[<p>Following my <a href="http://www.robsearles.com/2009/10/04/installing-php53-on-ubuntu-jaunty">previous post about installing PHP5.3 on Jaunty</a>, I have had a few requests about installing it on Karmic. I&#8217;ve never used Karmic before so I thought it would be a fun excuse to have a poke about whilst also keeping my blog (sort of) up-to-date.</p>
<p>After freshly installing Karmic (the desktop version looks very nice btw) on a new <a href="http://virtualbox.org/">VirtualBox</a> image and then updating with the latest, er, updates I was ready to begin.</p>
<p>The entire installation procedure is very simple, once all dependencies are met.</p>
<p>Firstly you must edit your sources list to include the <a href="http://www.dotdeb.org/">DotDeb package repository</a> and the old Jaunty security packages to meet dependencies.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># php5.3</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all
deb http:<span style="color: #000000; font-weight: bold;">//</span>security.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu jaunty-security main</pre></div></div>

<p>Now update and upgrade Ubuntu</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> upgrade</pre></div></div>

<p>You may find that you get the following warning:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">WARNING: The following packages cannot be authenticated<span style="color: #000000; font-weight: bold;">!</span>
libevent-<span style="color: #000000;">1.4</span>-<span style="color: #000000;">2</span>
Install these packages without verification <span style="color: #7a0874; font-weight: bold;">&#91;</span>y<span style="color: #000000; font-weight: bold;">/</span>N<span style="color: #7a0874; font-weight: bold;">&#93;</span>?</pre></div></div>

<p>I just answered Y and continued as normal</p>
<p>Once successfully upgraded then you can install Apache, MySQL and PHP as normal, feel free to cater the installation line to your tastes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libicu38 apache2 apache2-mpm-prefork mysql-client-<span style="color: #000000;">5.1</span> mysql-server-<span style="color: #000000;">5.1</span> php5 php5-cli php5-mysql libapache2-mod-php5</pre></div></div>

<p>You will get a warning about untrusted packages being installed but this simply means that the PHP5.3 stuff is not signed, so I typed in “yes” and carried on.</p>
<p>Robmorin <a href="http://www.robsearles.com/2009/10/04/installing-php53-on-ubuntu-jaunty/?dsq=40007017#comment-39744535">commented in my Jaunty post</a> that he had issues when installing PHP MCrypt. The answer can be found within the <a href="http://www.dotdeb.org/2009/07/03/php-5-3-0-final-preview-packages-available-for-debian-lenny/#comment-1077">DotDeb comments </a></p>
<p>After you have installed everything you need to, test it out, either command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ php <span style="color: #660033;">-v</span>
PHP 5.3.2-0.dotdeb.1 with Suhosin-Patch <span style="color: #7a0874; font-weight: bold;">&#40;</span>cli<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>built: Mar  <span style="color: #000000;">9</span> <span style="color: #000000;">2010</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">14</span>:<span style="color: #000000;">53</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1997</span>-<span style="color: #000000;">2009</span> The PHP Group
Zend Engine v2.3.0, Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1998</span>-<span style="color: #000000;">2010</span> Zend Technologies with Suhosin v0.9.29, Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">2007</span>, by SektionEins GmbH</pre></div></div>

<p>Or by using phpinfo() page within your Apache installation:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>info.php</pre></div></div>

<p>&lt;?PHP<br />
phpinfo();<br />
?&gt;</p>
<p>then fire up http://localhost/info.php and at the top of the page you should see something along the lines of<br />
<strong>PHP Version 5.3.2-0.dotdeb.1</strong></p>
<p>Note: if your browser asks if you want to download info.php, simply restart Apache and try again:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p>All done. Not quite as simple as on Jaunty, but still better than compiling the source!</p>
<p>Post Script: Before starting this post, I did a quick search looking for tutorials to see if the work had already been done, but couldn&#8217;t find anything on installing PHP5.3 on Karmic. As there wasn&#8217;t anything I decided to continue with my tutorial and I ended up struggling for an hour or so with the dependency issues. Typically, after I had figured it out for myself, whilst searching for another dependency issue I found <a href="http://blog.jmoz.co.uk/post/435401471/install-php-5-3-on-ubuntu-karmic-koala-from-dotdeb">this post on the JMOZ blog about installing PH5.3 on Karmic Koala</a>.  No idea why it&#8217;s not in Google, but either way, damn, I could have saved myself an hour or so!</p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=275&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2010/03/17/installing-php5-3-on-ubuntu-karmic/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Understanding Bitwise Operators (hopefully)</title>
		<link>http://www.robsearles.com/2009/12/04/understanding-bitwise-operators-hopefully/</link>
		<comments>http://www.robsearles.com/2009/12/04/understanding-bitwise-operators-hopefully/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 23:13:02 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=256</guid>
		<description><![CDATA[After the trouble I had with bitwise operators yesterday I found some time to really sit down and get my head properly around them. Let&#8217;s dive straight in.
We need to initially define our flags:

define&#40;'BASE', 0&#41;; // binary 00000000
define&#40;'F1', 1&#41;;   // binary 00000001
define&#40;'F2', 2&#41;;   // binary 00000010
define&#40;'F3', 4&#41;;   // binary 00000100

To start with we have no [...]]]></description>
			<content:encoded><![CDATA[<p>After the <a href="http://www.robsearles.com/2009/12/02/bitwise-operators-used-for-flagging-items-part-1/">trouble I had with bitwise operators yesterday</a> I found some time to really sit down and get my head properly around them. Let&#8217;s dive straight in.</p>
<p>We need to initially define our flags:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'BASE'</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// binary 00000000</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'F1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;   <span style="color: #666666; font-style: italic;">// binary 00000001</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'F2'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>;   <span style="color: #666666; font-style: italic;">// binary 00000010</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'F3'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span>;   <span style="color: #666666; font-style: italic;">// binary 00000100</span></pre></div></div>

<p>To start with we have no flags set, so if we set F1 using the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$f1_set</span> <span style="color: #339933;">=</span> BASE <span style="color: #339933;">+</span> F1; <span style="color: #666666; font-style: italic;">// $f1_set = 1</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;F1 set = $f1_set<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>All is well and good, $f1_set = 1 as expected.</p>
<p>However, what if we set F1 again?</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$f1_set_twice</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_set</span> <span style="color: #339933;">+</span> F1; <span style="color: #666666; font-style: italic;">// $f1_set_twice = 2 !!! wrong !!!</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;F1 set twice = $f1_set_twice<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>As you can see, if we set F1 twice, it effectively &#8220;unsets&#8221; F1 and sets F2. Not what we were after.</p>
<p>So why is this? Well, it&#8217;s kind of obvious and I was being a bit of a muppet for not spotting it yesterday. The reason is pretty simple: 1 + 1 = 2. (I told you it was obvious!)</p>
<p>Clearly this is not what we want, but how can we solve this? By using the bitwise OR. If we change the statements slightly as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$f1_or_set</span> <span style="color: #339933;">=</span> BASE | F1; <span style="color: #666666; font-style: italic;">// $f1_or_set = 1</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;F1 OR set = $f1_or_set<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$f1_or_set_twice</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_or_set</span> | F1; <span style="color: #666666; font-style: italic;">// $f1_or_set_twice = 1 - huzzah!</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;F1 OR set twice = $f1_or_set_twice<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>As far as &#8220;unsetting&#8221; the flags if we use my original method we fall (again) into trouble.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">=</span> BASE | F1 | F3; <span style="color: #666666; font-style: italic;">// $f1_and_f3 = 5;</span>
<span style="color: #000088;">$unset_f3</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">-</span> F3; <span style="color: #666666; font-style: italic;">// $unset_f3 = 1</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Unset F3 = $unset_f3<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$unset_f1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">-</span> F1; <span style="color: #666666; font-style: italic;">// $unset_f1 = 4;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Unset F1 = $unset_f1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>Now, if we try to &#8220;unset&#8221; F1 twice, we arrive at the problem.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$unset_f1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">-</span> F1; <span style="color: #666666; font-style: italic;">// $unset_f1 = 3;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Unset F1 = $unset_f1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>Unsetting F1 twice here effectively turns off F3 and sets F1 and F2 &#8211; completely wrong!</p>
<p>Instead, if we use the &amp;~ binary operator mentioned in <a href="http://www.robsearles.com/2009/12/02/bitwise-operators-used-for-flagging-items-part-1/#disqus_thread">Jesper&#8217;s comment</a> all works as expected. (note: I can&#8217;t find mention of this operator in the PHP docs, please someone help me out)</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">=</span> BASE | F1 | F3; <span style="color: #666666; font-style: italic;">// $f1_and_f3 = 5;</span>
<span style="color: #000088;">$unset_f3</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">&amp;</span>amp;~ F3; <span style="color: #666666; font-style: italic;">// $unset_f3 = 1</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Unset F3 = $unset_f3<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$unset_f1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">&amp;</span>amp;~ F1; <span style="color: #666666; font-style: italic;">// $unset_f1 = 4;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Unset F1 = $unset_f1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>Even if we try to &#8220;unset&#8221; a flag twice, it still has the same results:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$unset_f1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_and_f3</span> <span style="color: #339933;">&amp;</span>amp;~ F1; <span style="color: #666666; font-style: italic;">// $unset_f1 = 4;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Unset F1 = $unset_f1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$unset_f1_twice</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$unset_f1</span> <span style="color: #339933;">&amp;</span>amp;~ F1; <span style="color: #666666; font-style: italic;">// $unset_f1_twice = 4;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Unset F1 twice = $unset_f1_twice<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>Also in Jesper&#8217;s comment and <a href="http://noehr.org/2009/08/27/bitwise-permissions-in-python-and-django/">original post</a> was the use of the left shift operator: &lt;&lt;. After playing around with this it seems very simple to use, as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$f1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>;    <span style="color: #666666; font-style: italic;">// 00000001</span>
<span style="color: #000088;">$f2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>; <span style="color: #666666; font-style: italic;">// 00000010</span>
<span style="color: #000088;">$f3</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">2</span>; <span style="color: #666666; font-style: italic;">// 00000100</span>
<span style="color: #000088;">$f4</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">3</span>; <span style="color: #666666; font-style: italic;">// 00001000</span></pre></div></div>

<p>Or to put it another way:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$f1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>;      <span style="color: #666666; font-style: italic;">// 00000001</span>
<span style="color: #000088;">$f2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>; <span style="color: #666666; font-style: italic;">// 00000010</span>
<span style="color: #000088;">$f3</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f2</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>; <span style="color: #666666; font-style: italic;">// 00000100</span>
<span style="color: #000088;">$f4</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f3</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>; <span style="color: #666666; font-style: italic;">// 00001000</span></pre></div></div>

<p>After all this I think I am a little closer to understanding Bitwise operations, hopefully! Tomorrow I&#8217;ll have a crack at testing to see if a flag is turned on or not. Until then&#8230;</p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=256&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/12/04/understanding-bitwise-operators-hopefully/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bitwise Operators used for Flagging Items</title>
		<link>http://www.robsearles.com/2009/12/02/bitwise-operators-used-for-flagging-items-part-1/</link>
		<comments>http://www.robsearles.com/2009/12/02/bitwise-operators-used-for-flagging-items-part-1/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 17:34:21 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=245</guid>
		<description><![CDATA[I have always wondered what the point of Bitwise Operators were,to me they seem to belong to a distant past. However, after reading a couple of great blog posts I have at last an understanding of how they can be put to use, and have started playing around with them a bit (ba dum!).]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: Thanks to <a href="http://noehr.org/">Jesper Noehr</a> of <a href="http://bitbucket.org/">BitBucket</a> fame for pointing out <strong>gaping flaws</strong> in my post below (<a href="/2009/12/02/bitwise-operators-used-for-flagging-items-part-1/#disqus_thread">see his comment</a>). I strongly advise you disregard all I have said below, because it will get you into a mess, in much the same way it has me. I&#8217;m going to sit down when I have a spare 1/2 hour and try to work out exactly what is going on! Many thanks and big kudos to Jesper, I really appreciate the time you took to correct me.</p>
<hr />
<p>I have always wondered what the point of <a href="http://en.wikipedia.org/wiki/Bitwise_operation">Bitwise Operators</a> were,to me they seem to belong to a distant past. However, after reading a couple of great blog posts I have at last an understanding of how they can be put to use, and have started playing around with them a bit (ba dum!).</p>
<p>Jesper Noehr has written about using <a href="http://noehr.org/2009/08/27/bitwise-permissions-in-python-and-django/">bitwise operators for a flexible permissions scheme</a> within Python  and Jonathan Snook has taken the bitwise concept further creating a <a href="http://snook.ca/archives/javascript/creative-use-bitwise-operators">great calendar app in Javascript</a>. After reading these I thought I better dive in, and an opportunity came along yesterday when I had to code a flagging system within PHP.</p>
<p><span id="more-245"></span></p>
<p>For the benefit of this post I have greatly simplified the problem but hopefully it should be enough to get an understanding and allow you to get started with playing around with bits.</p>
<p>The problem is as follows. I have a number of items and each item has 3 different flags associated with it. We&#8217;ll call these flags F1, F2 and F3. A single item can have none, some or all flags set, and needs to have the ability to turn each flag on or off independently. The &#8220;base&#8221; state for each item is that no flags are set.</p>
<p>Each flag is a boolean, on or off, or to put it another way, 1 or 0. This translates perfectly into binary numerals. If we visualise this with a number of examples:</p>
<p><strong>No flags switched on</strong></p>
<table class="tbl-border" border="1" cellspacing="2" cellpadding="2" width="50%">
<tbody>
<tr>
<td valign="top">F1</td>
<td valign="top">F2</td>
<td valign="top">F3</td>
<td valign="top">Binary Number</td>
</tr>
<tr>
<td valign="top">0</td>
<td valign="top">0</td>
<td valign="top">0</td>
<td valign="top">0</td>
</tr>
</tbody>
</table>
<p><strong>Just F1 switched on</strong></p>
<table class="tbl-border" border="1" cellspacing="2" cellpadding="2" width="50%">
<tbody>
<tr>
<td valign="top">F1</td>
<td valign="top">F2</td>
<td valign="top">F3</td>
<td valign="top">Binary Number</td>
</tr>
<tr>
<td valign="top">1</td>
<td valign="top">0</td>
<td valign="top">0</td>
<td valign="top">001 or 1</td>
</tr>
</tbody>
</table>
<p><strong>Just F2 switched on</strong></p>
<table class="tbl-border" border="1" cellspacing="2" cellpadding="2" width="50%">
<tbody>
<tr>
<td valign="top">F1</td>
<td valign="top">F2</td>
<td valign="top">F3</td>
<td valign="top">Binary Number</td>
</tr>
<tr>
<td valign="top">0</td>
<td valign="top">1</td>
<td valign="top">0</td>
<td valign="top">010 or 10</td>
</tr>
</tbody>
</table>
<p><strong>Just F3 switched on</strong></p>
<table class="tbl-border" border="1" cellspacing="2" cellpadding="2" width="50%">
<tbody>
<tr>
<td valign="top">F1</td>
<td valign="top">F2</td>
<td valign="top">F3</td>
<td valign="top">Binary Number</td>
</tr>
<tr>
<td valign="top">0</td>
<td valign="top">0</td>
<td valign="top">1</td>
<td valign="top">100</td>
</tr>
</tbody>
</table>
<p><strong>F1 and F3 switched on</strong></p>
<table class="tbl-border" border="1" cellspacing="2" cellpadding="2" width="50%">
<tbody>
<tr>
<td valign="top">F1</td>
<td valign="top">F2</td>
<td valign="top">F3</td>
<td valign="top">Binary Number</td>
</tr>
<tr>
<td valign="top">1</td>
<td valign="top">0</td>
<td valign="top">1</td>
<td valign="top">101</td>
</tr>
</tbody>
</table>
<p>The reason we have translated the binary number for just F1 switched on to 001 and not 100 is because from a text point of view, we read F1, F2 then F3 from left to right, but from a numeric point of view we read numbers right to left, i.e. 1s then 10s then 100s then 1000s etc.</p>
<p>From the above examples, we can see that if F1 is already switched on, we can easily switch on F3 as well by simply turning on the F3 bit. We accomplish this by simply adding the F3 bit:<br />
Base + F1 + F3 = 0 + 1 + 100 = 000 + 001 + 100  = 101</p>
<p>We can also remove flags, for example if we have F3 and F1 set, but then remove F1 we have:<br />
101 &#8211; 001 = 101 &#8211; 1 = 100<br />
But even though these are all ones and noughts we can translate these into decimal. PHP has a handy little utility function for this: decbin() [http://php.net/manual/en/function.decbin.php]</p>
<table class="tbl-border" border="1" cellspacing="2" cellpadding="2" width="50%">
<tbody>
<tr>
<td valign="top">State</td>
<td valign="top">Binary</td>
<td valign="top">Decimal</td>
</tr>
<tr>
<td valign="top">All off</td>
<td valign="top">0</td>
<td valign="top">0</td>
</tr>
<tr>
<td valign="top">F1 on</td>
<td valign="top">1</td>
<td valign="top">1</td>
</tr>
<tr>
<td valign="top">F2 on</td>
<td valign="top">10</td>
<td valign="top">2</td>
</tr>
<tr>
<td valign="top">F3 on</td>
<td valign="top">100</td>
<td valign="top">4</td>
</tr>
<tr>
<td valign="top">F1 and F3 on</td>
<td valign="top">101</td>
<td valign="top">5 (1 + 4)</td>
</tr>
<tr>
<td valign="top">All on</td>
<td valign="top">111</td>
<td valign="top">7 (1 + 2 + 4)</td>
</tr>
</tbody>
</table>
<p>So now this makes it really easy to turn flags on an off.<br />
In PHP it would be as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'BASE'</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'F1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'F2'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="">'F3'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;No flags = &quot;</span><span style="color: #339933;">.</span>BASE<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">decbin</span><span style="color: #009900;">&#40;</span>BASE<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// switching flags on</span>
<span style="color: #000088;">$f1_on</span> <span style="color: #339933;">=</span> BASE<span style="color: #339933;">+</span>F1;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Turn on F1 = $f1_on:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">decbin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f1_on</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$f2_on</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f1_on</span><span style="color: #339933;">+</span>F2;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Turn on F2 = $f2_on:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">decbin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f2_on</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$f3_on</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f2_on</span><span style="color: #339933;">+</span>F3;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Turn on F3 = $f3_on:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">decbin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f3_on</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// switching flags off</span>
<span style="color: #000088;">$f2_off</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f3_on</span><span style="color: #339933;">-</span>F2;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Turn off F2 = $f2_off:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">decbin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f2_off</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$f1_off</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$f2_off</span><span style="color: #339933;">-</span>F1;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Turn off F1 = $f1_off:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">decbin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f1_off</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>Save this as bits.php and then run it from the command line with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ php .<span style="color: #000000; font-weight: bold;">/</span>bits.php
No flags = 0:0
Turn on F1 = <span style="color: #000000;">1</span>:<span style="color: #000000;">1</span>
Turn on F2 = <span style="color: #000000;">3</span>:<span style="color: #000000;">11</span>
Turn on F3 = <span style="color: #000000;">7</span>:<span style="color: #000000;">111</span>
Turn off F2 = <span style="color: #000000;">5</span>:<span style="color: #000000;">101</span>
Turn off F1 = <span style="color: #000000;">4</span>:<span style="color: #000000;">100</span></pre></div></div>

<p>All good so far, but now we need to see if a particular flag is switched on or off. I&#8217;ll publish that in my next blog post. So stay tuned.</p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=245&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/12/02/bitwise-operators-used-for-flagging-items-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Installing PHP5.3 on Ubuntu Jaunty</title>
		<link>http://www.robsearles.com/2009/10/04/installing-php53-on-ubuntu-jaunty/</link>
		<comments>http://www.robsearles.com/2009/10/04/installing-php53-on-ubuntu-jaunty/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 16:10:36 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=175</guid>
		<description><![CDATA[Install PHP5.3 on your Ubuntu LAMP stack in about 5 minutes]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: I have added a new <a href="http://www.robsearles.com/2010/03/17/installing-php5-3-on-ubuntu-karmic/">tutorial for installing PHP5.3 on Ubuntu Karmic</a>.</p>
<p>I have recently dusted off an old laptop to play around with and do some &#8220;fun&#8221; development. One of the things I have done to this laptop is to install a <a href="http://en.wikipedia.org/wiki/LAMP_(software_bundle)" target="_blank">LAMP</a> stack using <a href="http://www.php.net/releases/5_3_0.php" target="_blank">PHP 5.3</a> so I can play around and see what&#8217;s new and exciting.</p>
<p>I had a quick Google on how to install PHP 5.3 on Ubuntu and found <a href="http://www.brandonsavage.net/installing-php-5-3-on-ubuntu/" target="_blank">Brandon Savage&#8217;s post</a> on the very subject! Whilst he has a great write up it was one or two of his comments mentioning the <a href="http://www.dotdeb.org/2009/07/03/php-5-3-0-final-preview-packages-available-for-debian-lenny/" target="_blank">DotDeb.Org</a> package repository.</p>
<p>This was a breeze to use and in about 5 minutes I have PHP 5.3 running with Apache and MySQL on my clean Jaunty system.</p>
<p>The first thing to do is add the DotDeb.org repositories to your sources list:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># php5.3</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all</pre></div></div>

<p>Now update and upgrade Ubuntu</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> upgrade</pre></div></div>

<p>Now simply install apache mysql and php as usual</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2 apache2-mpm-prefork mysql-client-<span style="color: #000000;">5.1</span> mysql-server-<span style="color: #000000;">5.1</span> php5 php5-cli php5-mysql libapache2-mod-php5</pre></div></div>

<p>You will get a warning about untrusted packages being installed but this simply means that the PHP5.3 stuff is not signed, so I typed in &#8220;yes&#8221; and carried on. <em>Obviously you can cater this line to your specific needs, but this is the basic stack up and running</em></p>
<p>When it was all complete I tested out my system:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ php <span style="color: #660033;">-v</span>
PHP 5.3.0-0.dotdeb.8 with Suhosin-Patch 0.9.7 <span style="color: #7a0874; font-weight: bold;">&#40;</span>cli<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>built: Aug <span style="color: #000000;">12</span> <span style="color: #000000;">2009</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">11</span>:<span style="color: #000000;">27</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1997</span>-<span style="color: #000000;">2009</span> The PHP Group
Zend Engine v2.3.0, Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1998</span>-<span style="color: #000000;">2009</span> Zend Technologies</pre></div></div>

<p>and tested out my apache installation using a phpinfo() script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>info.php</pre></div></div>

<p>then fired up http://localhost/info.php<br />
<code lang="php">&lt;?PHP<br />
phpinfo();<br />
?&gt;</code><br />
and saw as the main header of the page:<br />
<strong>PHP Version 5.3.0-0.dotdeb.8</strong></p>
<p>All done. Simple!</p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=175&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/10/04/installing-php53-on-ubuntu-jaunty/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Wordpress: Multiple Content Columns</title>
		<link>http://www.robsearles.com/2009/07/05/wordpress-multiple-content-columns/</link>
		<comments>http://www.robsearles.com/2009/07/05/wordpress-multiple-content-columns/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 14:32:47 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=126</guid>
		<description><![CDATA[Wordpress template hack to split page content into multiple columns using the more tag]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a <a href="http://wordpress.org" target="_blank">Wordpress</a> site for a client with one of our developers <a href="http://www.thomashartnell.com/" target="_blank">Tom Hartnell</a>. The design of this particular site was that some pages would need content displayed over multiple columns. This content had to be updatable by the client, as such it could not be hard coded into the template files.</p>
<p>We had a look around and we found a potential solution on <a href="http://www.kriesi.at/archives/wordpress-display-content-in-multiple-columns" target="_blank">this blog pos</a>t.</p>
<p>We played around with this for a while but found that, whilst it was a good solution, it wasn&#8217;t quite suitable for our needs.  What we needed was a solution which allowed us to have any number of columns and for each column to contain completely different content. The solution in the post demanded that each column start with the same HTML tag (H2 in the example). We decided to rewrite the function described above, based on the same principals, but updated and improved so it would fit our needs.</p>
<p>To see what the end result is, you can see a <a href="/multiple-columns-page/" target="_blank">demo page</a>.</p>
<p><span id="more-126"></span></p>
<p>The first thing the new function had to do was to split the content into the different columns using the <strong>more</strong> tag. In our tests, we found that Wordpress replaced the more tag with a span, but only in the first instance, all the rest were kept as a comment tag. The regular expression we used had to take this into account.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// the first &quot;more&quot; is converted to a span with ID</span>
<span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="">'/(&lt;span id=&quot;more-\d+&quot;&gt;&lt;\/span&gt;)|(&lt;!--more--&gt;)&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This regular expression is not bullet proof, but it does the job for us. Specifically, if you are using a plugin like &#8220;Sociable&#8221; or something that appends stuff to the end of the content then this stuff will end up in the third column and not nicely across the bottom of the page. Also, it hasn&#8217;t been tested when adding images. These two issues weren&#8217;t going to be a problem for us, so the regular expression above is perfectly adequate for our needs.</p>
<p>Next we need to loop through each column, removing any stray &lt;p&gt; tags that may have been orphaned by the regular expression and putting the content into separate divs.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$col_count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$col_count</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// check to see if there is a final, if not add it</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="">'/&lt;\/p&gt;\s?$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="">'&lt;/p&gt;'</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// check to see if there is an appending, if there is, remove</span>
	<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="">'/^\s?&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #666666; font-style: italic;">// now add the div wrapper</span>
	<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="">'&lt;div class=&quot;dynamic-col-'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="">'&lt;/div&gt;'</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally we can join the columns back together to produce the final content.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;'</span>;</pre></div></div>

<p>Notice that we have added a clearing div here. This is basically so you can clear the floats with CSS so any content displayed below the page content will be correctly positioned.</p>
<p>What if there isn&#8217;t a more tag? We will only have one column. As such there is no need to modify the content, so the code above should go into an if statement</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$col_count</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The last job to do in this function is to clear out any blank &lt;p&gt; tags caused by the regular expression and return the content</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// remove any left over empty tags</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">'&lt;p&gt;&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span>;</pre></div></div>

<p>This would normally all be contained in a function (we called my_multi_col_v2) that would be called as a filter function, however, we found that this was causing problems with the Wordpress excerpts, so instead we are overriding the default content display function in the <strong>page.php</strong> file.<br />
In your page.php file, replace the line that calls the the_content() function</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//the_content('Read the rest of this entry &amp;raquo;');</span></pre></div></div>

<p>Now we collect the content into a variable, then pass this variable to the new function, outputting the result. The function that gets the content instead of directly outputting it is <a href="http://codex.wordpress.org/Function_Reference/get_the_content" target="_blank">get_the_content()</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="">''</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span><span style="">''</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">//arguments remove 'more' text</span>
<span style="color: #990000;">echo</span> my_multi_col_v2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>As we are using get_the_content() the default filtering that is normally done on the content is not being run. So at the top of our new function, we must manually run these</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// run through a couple of essential tasks to prepare the content</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">']]&gt;'</span><span style="color: #339933;">,</span> <span style="">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This also caused a problem with line breaks when only displaying one column, so we needed to include an else statement that ran <a href="http://codex.wordpress.org/Function_Reference/wpautop" target="_blank">wpautop() </a></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// this page does not have dynamic columns</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> wpautop<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So the final function looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_multi_col_v2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// run through a couple of essential tasks to prepare the content</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">']]&gt;'</span><span style="color: #339933;">,</span> <span style="">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// the first &quot;more&quot; is converted to a span with ID</span>
	<span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="">'/(&lt;span id=&quot;more-\d+&quot;&gt;&lt;\/span&gt;)|(&lt;!--more--&gt;)&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000088;">$col_count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$col_count</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$col_count</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// check to see if there is a final &lt;/p&gt;, if not add it</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="">'/&lt;\/p&gt;\s?$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="">'&lt;/p&gt;'</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// check to see if there is an appending &lt;/p&gt;, if there is, remove</span>
			<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="">'/^\s?&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #666666; font-style: italic;">// now add the div wrapper</span>
			<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="">'&lt;div class=&quot;dynamic-col-'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="">'&lt;/div&gt;'</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;'</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// this page does not have dynamic columns</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> wpautop<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// remove any left over empty &lt;p&gt; tags</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">'&lt;p&gt;&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The next thing to do is to update your CSS so it lays out the columns correctly. In the demo I have used three columns, and the CSS for it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* dynamic columns */</span>
div<span style="color: #6666ff;">.dynamic-col-1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">38</span>%</span>; <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">2</span>%</span>;<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.dynamic-col-2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">38</span>%</span>;padding-<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">2</span>%</span>;<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.dynamic-col-3</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">20</span>%</span>;<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.clear</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">both</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>And that&#8217;s pretty much it.  Have a look at <a href="/multiple-columns-page/" target="_blank">the demo</a>, below is a screenshot of the Wordpress editor screen so you can see that it really is controlled by the user, you should see the two more tags that are used to split the content into the three columns.</p>
<div id="attachment_128" class="wp-caption alignnone" style="width: 510px"><a href="http://www.robsearles.com/wp-content/uploads/2009/07/wordpress-multiple-cols.png"><img class="size-full wp-image-128" title="wordpress-multiple-cols" src="http://www.robsearles.com/wp-content/uploads/2009/07/wordpress-multiple-cols.png" alt="Wordpress multiple content columns, editor input" width="500" height="440" /></a><p class="wp-caption-text">Wordpress multiple content columns, editor input</p></div>
<p>Please feel free to take this, improve it, update it, completely rewrite it. If you do please can you drop me a comment and let me know. And a big thanks to <a href="http://www.kriesi.at/" target="_blank">Kriesi</a> for his initial work and for providing inspiration for this blog post.</pre>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=126&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/07/05/wordpress-multiple-content-columns/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>PHP5: Fake Method Overloading</title>
		<link>http://www.robsearles.com/2009/06/05/php5-fake-method-overloading/</link>
		<comments>http://www.robsearles.com/2009/06/05/php5-fake-method-overloading/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 08:44:35 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.robsearles.co.uk/?p=91</guid>
		<description><![CDATA[Been struggling for the past hour or so with method overloading within objects, so I thought I&#8217;d write a little not on my blog to hopefully help others and to remind myself.
The premise for this is that I was writing a new database wrapper class to speed up the rather rubbish database module I have [...]]]></description>
			<content:encoded><![CDATA[<p>Been struggling for the past hour or so with method overloading within objects, so I thought I&#8217;d write a little not on my blog to hopefully help others and to remind myself.</p>
<p>The premise for this is that I was writing a new database wrapper class to speed up the rather rubbish database module I have been using previously. My plan was to encapsulate all my methods in the wrapper (such as get_table_name() etc) in my class then all others fire off to the ADODB class by PHPlens. My plan was to do this with method overloading, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$m</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt;db<span style="color: #339933;">-&amp;</span>gt;<span style="color: #000088;">$m</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span>;
throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="">'Tried to call unknown method '</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt;db<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'::'</span><span style="color: #339933;">.</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>However, PHP5 doesn&#8217;t seem to support that, which is irritating. After some search on the web I find out that PHP5 doesn&#8217;t support real overloading.</p>
<p>So after much effort and searching the web and docs I decide to use the call_user_func_array(&amp;obj) technique.</p>
<p>Finished method below:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$m</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// check the method being called exists</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt;db<span style="color: #339933;">,</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp;<span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt;db<span style="color: #339933;">,</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="">'Tried to call unknown method '</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt;db<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'::'</span><span style="color: #339933;">.</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Seems to work, so please feel free to use</p>
<p><em>Note: This post has been copied from the old <a href="http://www.ibrow.com/" target="_blank">ibrow.com</a> website, originally posted on </em>2007-07-04<em>. See <a href="../2009/05/14/updating-ibrowcom-moving-old-blog-entries/">this entry</a> for more details</em></p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=91&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/06/05/php5-fake-method-overloading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana PHP Framework &#8211; My Thoughts</title>
		<link>http://www.robsearles.com/2009/01/25/kohana-php-framework-my-thoughts/</link>
		<comments>http://www.robsearles.com/2009/01/25/kohana-php-framework-my-thoughts/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 21:59:37 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[kohana]]></category>

		<guid isPermaLink="false">http://www.robsearles.co.uk/?p=64</guid>
		<description><![CDATA[My thoughts after several weeks using the Kohana PHP framework.]]></description>
			<content:encoded><![CDATA[<p>As some of you know, over the past few weeks I&#8217;ve been building a prototype for a new web app. For this I decided to try out the <a href="http://www.kohanaphp.com" target="_blank">Kohana PHP framework </a>to see if it will help speed up development. I chose Kohana primarily because it was light weight and PHP5 only, and I have to say I&#8217;m really glad I did. After several weeks hacking around with Kohana (mostly playing admitedly, but I&#8217;m almost to the point of having a fully working web app up and running) I have collected a few thoughts on the framework.</p>
<h3>Good Points</h3>
<ul>
<li>It is PHP5 only (5.2 and above) so it allows for utilising the full power of OO PHP.</li>
<li> It is light weight.</li>
<li> True auto loading &#8211; it&#8217;s PHP5, you shouldn&#8217;t have to explicate load a class!</li>
<li> The cascading file system &#8211; this is a joy to work with. It easily allows you to extend and add to modules, libraries, models and configuration files.</li>
<li>Kohana has greatly speeded up the development of my prototype and has allowed me to focus on the actual functionality of the app, leaving all the boring, repetitive bits of coding to the framework.</li>
<li>I have had to dig about under the bonnet a few times to see what&#8217;s going on, and I have been impressed by the clean and well structured code.</li>
<li> The community &#8211; behind Kohana there is a small but active and knowledgeable community. I have been stuck a <a href="http://forum.kohanaphp.com/comments.php?DiscussionID=1809" target="_blank">number </a>of <a href="http://forum.kohanaphp.com/comments.php?DiscussionID=1932" target="_blank">times </a>when hacking around with Kohana, and on both occasions I have received prompt and useful replies.</li>
<li> Most importantly it lets you code how you want, without getting in the way, whilst at the same time can take out a lot of the donkey work for repetitive tasks.</li>
</ul>
<h3>Bad Points</h3>
<p>This is going to be difficult, but I&#8217;ll give it a try</p>
<ul>
<li><a href="http://docs.kohanaphp.com/" target="_blank">Documentation</a>.  From what I can make out it has come on leaps and bounds over the past few months, however, it sometimes isn&#8217;t always clear. Also, the <a href="http://learn.kohanaphp.com/" target="_blank">tutorial site </a>hasn&#8217;t been updated for a good few months now.</li>
<li>Limited number of modules currently available.</li>
</ul>
<p>However, the above points aren&#8217;t deal breakers. Kohana is an open source project, and relatively young at that. This means that I can actively do something about both the documentation (it&#8217;s a wiki that anyone can register) and the modules. I just need to find some time and <a href="http://learn.kohanaphp.com/" target="_blank">contribute</a>!</p>
<h3>Conclusion</h3>
<p>As you might already be able to tell, my conclusion is going to be positive. I have really enjoyed playing around with Kohana, it is solid, secure and well designed. Being <a href="http://www.gophp5.org/projects" target="_blank">PHP5 only</a>, not only can I utilise the full potential of PHP, but so can the framework. As said, I&#8217;m really glad I chose Kohana, and I am pretty excited about its <a href="http://forum.kohanaphp.com/comments.php?DiscussionID=1605" target="_blank">future developments</a>.</p>
<p>If anyone out there needs a solid, well thought out framework for PHP5, that is backed by an active community, you can&#8217;t go wrong if you chose Kohana.</p>
<h3>Notes</h3>
<p>I have been using Kohana version 2.3 exported from the SVN &#8211; details on the <a href="http://dev.kohanaphp.com/" target="_blank">Kohana dev site</a>.</p>
<h3>Other Reviews</h3>
<p>Don&#8217;t take my word for it, other people are talking about Kohana too</p>
<ul>
<li>Review at <a href="http://www.phoenixheart.net/2009/01/kohana-php-framework/" target="_blank">phoenixheart.net</a> &#8211; very recent so a good review of the state that Kohana is in at the moment.</li>
<li>The <a href="http://www.paulrouke.co.uk/2008/08/15/php-framework-comparison-kohana/" target="_blank">final part of a review </a>comparing <a href="http://zendframework.com/" target="_blank">Zend</a>, <a href="http://www.symfony-project.org/" target="_blank">Symfony </a>and Kohana. This review is about 6 months old, so the comments about the lack of documentation are slightly less accurate today.</li>
<li><a href="http://www.beyondcoding.com/2008/02/23/notes-on-choosing-a-php-framework-a-quick-comparison-of-codeigniter-and-kohana/" target="_blank">Comparision </a>of Kohana and <a href="http://codeigniter.com/" target="_blank">CodeIgnitor </a>(the framework Kohana was originally forked from).</li>
</ul>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=64&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/01/25/kohana-php-framework-my-thoughts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up XDebug for PHP in Ubuntu Intrepid Ibex</title>
		<link>http://www.robsearles.com/2009/01/13/setting-up-xdebug-for-php-in-ubuntu-intrepid-ibex/</link>
		<comments>http://www.robsearles.com/2009/01/13/setting-up-xdebug-for-php-in-ubuntu-intrepid-ibex/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 16:17:04 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.robsearles.co.uk/?p=59</guid>
		<description><![CDATA[I love Ubuntu and today reminded me exactly why. It&#8217;s just so easy to do stuff in it!
I run a LAMP development server off my laptop, and today some of the PHP I was writing was throwing up some errors. Unfortunately I hadn&#8217;t installed XDebug which makes life so much easier when debugging PHP.
Oh no, [...]]]></description>
			<content:encoded><![CDATA[<p>I love Ubuntu and today reminded me exactly why. It&#8217;s just so easy to do stuff in it!</p>
<p>I run a LAMP development server off my laptop, and today some of the PHP I was writing was throwing up some errors. Unfortunately I hadn&#8217;t installed XDebug which makes life so much easier when debugging PHP.</p>
<p>Oh no, I though. I&#8217;ll have to download it, install it, update the PHP.ini file. Argh.</p>
<p>But wait&#8230;no! I have Ubuntu, all it took was 2 easy steps:</p>
<p><strong>Step 1, install Xdebug</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-xdebug</pre></div></div>

<p><strong>Step 2, restart Apache</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p>Done! Easy peasy.</p>
<p>Thanks Ubuntu <img src='http://www.robsearles.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=59&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/01/13/setting-up-xdebug-for-php-in-ubuntu-intrepid-ibex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
