<?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>Photogabble &#187; PHP</title>
	<atom:link href="http://photogabble.co.uk/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://photogabble.co.uk</link>
	<description>photoblog of simon dann</description>
	<lastBuildDate>Sun, 25 Dec 2011 14:19:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Tiny Javascript WYSIWYG Editor</title>
		<link>http://photogabble.co.uk/php/tiny-javascript-wysiwyg-editor.html</link>
		<comments>http://photogabble.co.uk/php/tiny-javascript-wysiwyg-editor.html#comments</comments>
		<pubDate>Tue, 06 Apr 2010 22:23:06 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Tiny Editor]]></category>
		<category><![CDATA[wysiwyg]]></category>

		<guid isPermaLink="false">http://photogabble.co.uk/?p=3451</guid>
		<description><![CDATA[If you search google for &#8220;wysiwyg JavaScript&#8221; you will find many full feature &#8220;what you see is what you get&#8221; editors written in JavaScript and developed for use within html forms. However many of these have dependencies upon external libraries such as jQuery or simply have everything plus the kitchen sink included; if your developing [...]]]></description>
			<content:encoded><![CDATA[<p>If you search google for &#8220;wysiwyg JavaScript&#8221; you will find many full feature &#8220;what you see is what you get&#8221; editors written in JavaScript and developed for use within html forms. However many of these have dependencies upon external libraries such as jQuery or simply have everything plus the kitchen sink included; if your developing an online word processor this many not be much of a problem to you however within the recent development work I have been involved in I just needed a good quality WYSIWYG editor, written in JavaScript and with only the basic text formatting features included. I am still unsure how I stumbled upon <a href="http://www.leigeber.com/2010/02/javascript-wysiwyg-editor/">TinyEditor</a> by Leighber, however stumble I did and it has proven perfect for my simplistic needs while having a few more extensive features for future expansion only when required and best of all it is a stand-alone package!</p>
<p>Other WYSIWYG editors I discovered and tested during my hunt where the jQuery based <a title="JQYSIWYG at google code" href="http://code.google.com/p/jwysiwyg/">jwysiwyg project</a> and the more complex <a title="WYMEDITOR Home page" href="http://www.wymeditor.org/">wymeditor</a>. While these were too complex for my needs they do work quite well and I would recommend you give them a go before making your mind up.</p>
<p>The one problem I do I have with TinyEditor is the unfortunate lack of a paste from word feature, I am hoping that this does become included soon because it is the only additional feature that is a must with WYSIWYG HTML editors due to paste from word screwing your nicely formatted code up upon submit.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/php/tiny-javascript-wysiwyg-editor.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Print Array</title>
		<link>http://photogabble.co.uk/asides/php-print-array.html</link>
		<comments>http://photogabble.co.uk/asides/php-print-array.html#comments</comments>
		<pubDate>Thu, 24 Sep 2009 14:08:38 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tid-bits]]></category>

		<guid isPermaLink="false">http://photogabble.co.uk/?p=2742</guid>
		<description><![CDATA[For future reference print_r($array) dumps the contence of an array, very useful for debugging things.]]></description>
			<content:encoded><![CDATA[<p>For future reference<code> print_r($array)</code> dumps the contence of an array, very useful for debugging things.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/asides/php-print-array.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPGraphLib</title>
		<link>http://photogabble.co.uk/asides/phpgraphlib.html</link>
		<comments>http://photogabble.co.uk/asides/phpgraphlib.html#comments</comments>
		<pubDate>Thu, 13 Aug 2009 21:18:12 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://photogabble.co.uk/?p=2383</guid>
		<description><![CDATA[PHPGraphLib is amazing, simply put. While not exactly brimming with features, it does what it says on the tin and it does it very well! Already utilized it in a few of my scripts for easy visualization]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ebrueggeman.com/phpgraphlib/">PHPGraphLib</a> is amazing, simply put. While not exactly brimming with features, it does what it says on the tin and it does it very well! Already utilized it in a few of my scripts for easy visualization <img src='http://photogabble.co.uk/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/asides/phpgraphlib.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to cut down wordpress memory usage.</title>
		<link>http://photogabble.co.uk/php/how-to-cut-down-wordpress-memory-usage.html</link>
		<comments>http://photogabble.co.uk/php/how-to-cut-down-wordpress-memory-usage.html#comments</comments>
		<pubDate>Tue, 11 Aug 2009 15:35:34 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[memory use]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://photogabble.co.uk/?p=2336</guid>
		<description><![CDATA[Photogabble is similar to many other websites in that it is managed via an installation of word-press; word-press by and large is a very good blogging platform, indeed I would say it is one of &#8211; if not &#8211; thee best blogging platform available today quite simply for its simplicity, its script-ability and ease of [...]]]></description>
			<content:encoded><![CDATA[<p>Photogabble is similar to many other websites in that it is managed via an installation of word-press; word-press by and large is a very good blogging platform, indeed I would say it is one of &#8211; if not &#8211; <em>thee</em> best blogging platform available today quite simply for its simplicity, its script-ability and ease of designing for. However there is one draw back, as with everything around us, wordpress is not perfect; indeed the average install alongside its additional plug-ins and add-ons seems to consume copious amounts of system memory which is <strong>bad</strong>! While I am lucky to have built my server from scratch it still has limitations the most important of which being memory, a whole 2GB of it.</p>
<p>Up until I completed the following quick fix, wordpress was using almost 30MB per instance, this means that I could only at peak have 66 or so visitors at the same time before my server became overrun and hid under the bed. What I needed to do was supercharge php and the easiest way to do that is by caching. Thanks to <a href="http://itst.net/654-php-on-fire-three-opcode-caches-compared">this interesting article</a> on php caching by itst.net I chose <a href="http://pecl.php.net/package/APC">APC </a>(Alternative PHP Cache) which is supported by the php foundation and showed the most promising speed improvements.</p>
<p>Installing APC really couldn&#8217;t have been made any easier on debian; it does require some dependencies, obviously php 5.x plus the pear package installed but apart from that not much else is needed to be installed and it you use apt-get they are installed as part of the installation process. The instillation process is as simple as follows:<br />
<code>
<pre>apt-get install php-apc
<br/>
/etc/init.d/apache2 restart</pre>
<p></code><br />
Once APC has been installed and apache restarted you can issue the following command to ensure that it has installed correctly:</p>
<pre><code>php -r 'phpinfo();' | grep apc</code></pre>
<p>Once that has been done and you get a positive response to the above command you should see that wordpress is using considerably less memory. My install with its 16 or so plugins now uses 3.16MB rather than almost 30MB! That is what you call a good improvement.</p>
<p>One draw back with apc as with many caching processes is that it does cause an initial increased draw on the processor while it compiles the php into an performance enhanced executable file and stores it in a ram disk however once this intial process it done you can stand to see upto 200% increase in performance and a severely reduced memory footprint for each of your php apps.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/php/how-to-cut-down-wordpress-memory-usage.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress: get_post_ancestors()</title>
		<link>http://photogabble.co.uk/php/wordpress-get_post_ancestors.html</link>
		<comments>http://photogabble.co.uk/php/wordpress-get_post_ancestors.html#comments</comments>
		<pubDate>Fri, 17 Apr 2009 13:15:43 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[flag]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://photogabble.co.uk/?p=1370</guid>
		<description><![CDATA[In adding a few slight modifications to the photogabble theme and because a design I&#8217;m working on for someone else required it; I managed to stumble upon a ridiculously simple solution to a over complected problem, how to find the post parent when the child post is more than one level deep. I had been [...]]]></description>
			<content:encoded><![CDATA[<p>In adding a few slight modifications to the photogabble theme and because a design I&#8217;m working on for someone else required it; I managed to stumble upon a ridiculously simple solution to a over complected problem, how to find the post parent when the child post is more than one level deep.</p>
<p>I had been using the following code to do this:</p>
<pre>if($post-&gt;post_parent=="11"{ ... }</pre>
<p>While this simple switch works if you are one layer deep for example Fish (ID 11) &gt; Tropical Fish (ID 12) it wont work if your more than two layers deep such as Fish (ID 11) &gt; Tropical Fish (ID 12) &gt; Amazon Fish (ID 13) because $post_post_parent for Amazon Fish becomes 12 not 11. In terms of programming this is all very logical, however the solution to finding out the original post_parent otherwise known as the grandparent or great grandparent is not very well documented and it was only luck that helped me stumble upon it. The very simple function get_post_ancestors() solves this problem by effectively returning an array with every post id related to the one in which it was called as the following example shows:</p>
<pre>$ancestors = get_post_ancestors();</pre>
<p>$ancestors now becomes an array which we can search through the php <a href="http://php.net/in_array">in_array</a> command by the following code:</p>
<pre>in_array(11,$ancestors);</pre>
<p>In this example if one of the $post_id&#8217;s of the current posts ancestors is 11 then the in_array function will return with true, otherwise it will return false. This then makes showing information on all sub pages (child pages) of Fish(ID 11) a simple matter of using the following code:</p>
<pre>$ancestors = get_post_ancestors($post);
if(in_array(11,$ancestors)){
	...
}</pre>
<p>I use this on my <a href="http://photogabble.co.ukprojects/">projects page&#8217;s</a> to provide a link back to the projects page from the sidebar of all its children, it could also be used to show a custom header for that section of your blog or certain links from a link category relevant to that section. The usefulness of this function is never ending and should be one of many you use when writing your own templates.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/php/wordpress-get_post_ancestors.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Setup PHP with cURL</title>
		<link>http://photogabble.co.uk/php/setup-php-with-curl.html</link>
		<comments>http://photogabble.co.uk/php/setup-php-with-curl.html#comments</comments>
		<pubDate>Wed, 15 Apr 2009 19:32:41 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://photogabble.co.uk/?p=1309</guid>
		<description><![CDATA[I recently upgraded my server from php4 to php5, I did the usual basic php5 install using apt-get and have had to add various libraries as and when I need them. Doing this is relatively simple on debian with the apt-get command. Simply enter the following into your terminal session: sudo apt-get install curl libcurl3 [...]]]></description>
			<content:encoded><![CDATA[<p>I recently upgraded my server from php4 to php5, I did the usual basic php5 install using apt-get and have had to add various libraries as and when I need them. Doing this is relatively simple on debian with the apt-get command. Simply enter the following into your terminal session:</p>
<pre>sudo apt-get install curl libcurl3 libcurl3-dev php5-curl</pre>
<p>If you dont have sudo installed then simply enter it without then enter the following to reboot your apache server for the changes to take effect.</p>
<pre>sudo /etc/init.d/apache2 restart</pre>
<p>Again if you dont have sudo installed then remove it from the line before you press return and cURL will be fully working &#8211; enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/php/setup-php-with-curl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a template for Cube Cart.</title>
		<link>http://photogabble.co.uk/design/writing-a-template-for-cube-cart.html</link>
		<comments>http://photogabble.co.uk/design/writing-a-template-for-cube-cart.html#comments</comments>
		<pubDate>Sat, 14 Jun 2008 17:14:59 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cubecart]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://photogabble.co.uk/?p=679</guid>
		<description><![CDATA[My most recent client project spec is to produce an online shop, while this initially didn&#8217;t appear to be an issue for me as I am quite able to create the design. I never once thought how difficult it would be to code the template for that design. It appears that while there are only [...]]]></description>
			<content:encoded><![CDATA[<p>My most recent client project spec is to produce an online shop, while this initially didn&#8217;t appear to be an issue for me as I am quite able to create the design. I never once thought how difficult it would be to code the template for that design. It appears that while there are only a hand-full of useful online shop software packages they each use a complex and rarely documented templating system. For this project I have chosen cube cart as it includes many of the mechanisms that my client requires and out of those I have tested it appears to be the most stable and &#8220;easy&#8221; to design for. I suppose to the first time on looker, the template system utilized by WordPress would be a little confusing and while I find it easy to use, I have been working with WordPress for a considerable number of years. I only hope I can get to knowing how to use the Cube Cart template system as easily as I did with WordPress. Has anyone else developed for cube cart and do you know of any online documentation I may find of use as google has given me nothing but multiple template websites trying to sell me something.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/design/writing-a-template-for-cube-cart.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Board Fixed</title>
		<link>http://photogabble.co.uk/tumblrs/image-board-fixed.html</link>
		<comments>http://photogabble.co.uk/tumblrs/image-board-fixed.html#comments</comments>
		<pubDate>Tue, 11 Mar 2008 02:07:53 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[Tumblrs]]></category>
		<category><![CDATA[photogabble]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.photogabble.co.uk/2008/03/11/image-board-fixed/</guid>
		<description><![CDATA[It took me five minutes to fix something that had been broken for almost a year, I had been baffled why it had broken in the first place before I read about php&#8217;s updates. Silly developers moving date functions about&#8230; Still photogabble.co.ukprojects/images/ now works.]]></description>
			<content:encoded><![CDATA[<p>It took me five minutes to fix something that had been broken for almost a year, I had been baffled why it had broken in the first place before I read about php&#8217;s updates. Silly developers moving date functions about&#8230; Still <a href="http://photogabble.co.ukprojects/images/" title="Project images">photogabble.co.ukprojects/images/</a> now works.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/tumblrs/image-board-fixed.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Memory Bugfix</title>
		<link>http://photogabble.co.uk/technical/php-memory-bugfix.html</link>
		<comments>http://photogabble.co.uk/technical/php-memory-bugfix.html#comments</comments>
		<pubDate>Fri, 07 Sep 2007 15:12:52 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[bugfix]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[memory-limit]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.photogabble.co.uk/2007/09/07/php-memory-bugfix/</guid>
		<description><![CDATA[Today after updating the programs running on my server to the latest builds I was met with the following error presented by wordpress: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 79 bytes) Upon doing the usual google, I discovered a few people have been having the same problem as myself. [...]]]></description>
			<content:encoded><![CDATA[<p>Today after updating the programs running on my server to the latest builds I was met with the following error presented by wordpress:</p>
<blockquote><p>Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 79 bytes)</p></blockquote>
<p>Upon doing the usual google, I discovered a few people have been having the same problem as myself. It is however a very easy problem to fix and although I found no actual answers on the net (obviously I didn&#8217;t look hard enough) I figured it out in the end. The problem is caused by scripts requiring more memory to execute than php has available to it. By default php limits itself to 8MB and usually that is enough with which to run most scripts, however either by some error of php or the new heavier than usual requirements of todays scripts sometimes 8MB is just not enough and as you can see in my example only 79 bytes extra where needed.</p>
<p>The fix is simple, find your php.ini file open it and find the Resource Limits section. Under that heading there is a line which by default says:</p>
<blockquote><p>memory_limit = 8M    ;Maximum amount of memory a script may consume (8MB)</p></blockquote>
<p>All you need to do is change the 8M to 16M, I know that the problem is caused by scripts only needing a few extra bytes but its always nice to have a multiple of the original therefore I have doubled it, you needn&#8217;t do this changing it to 9M will fix  the problem. Once you have made the changes save the file and exit then restart your server process which in my case is apache and the problem will be fixed and all your scripts will be working <img src='http://photogabble.co.uk/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Feel free to comment if you have any other questions about this topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/technical/php-memory-bugfix.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>time_since</title>
		<link>http://photogabble.co.uk/php/time_since.html</link>
		<comments>http://photogabble.co.uk/php/time_since.html#comments</comments>
		<pubDate>Fri, 20 Apr 2007 01:14:28 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[time_since]]></category>

		<guid isPermaLink="false">http://www.photogabble.co.uk/2007/04/20/time_since/</guid>
		<description><![CDATA[I found it incredibly difficult to find any form of time_since function in php so to save anyone else the trouble to hunting through hundreds of useless websites here is the function you may want to use, written by Natalie Downe (you don&#8217;t want to know how long it took to hunt it down). It [...]]]></description>
			<content:encoded><![CDATA[<p>I found it incredibly difficult to find any form of time_since function in php so to save anyone else the trouble to hunting through hundreds of useless websites here is the function you may want to use, written by <a href="http://notes.natbat.net/2007/01/27/timesince/">Natalie Downe</a> (you don&#8217;t want to know how long it took to hunt it down). It takes the input in the form of the unix time stamp.</p>
<pre><code>function time_since($original) {

// array of time period chunks

$chunks = array(

array(60 * 60 * 24 * 365 , 'year' ),

array(60 * 60 * 24 * 30 , 'month' ),

array(60 * 60 * 24 * 7, 'week' ),

array(60 * 60 * 24 , 'day' ),

array(60 * 60 , 'hour' ),

array(60 , 'minute' ),

);</code><code>$today = time(); /* Current unix time */

$since = $today - $original;</code>

<code>// $j saves performing the count function each time around the loop

for ($i = 0, $j = count($chunks); $i &lt; $j; $i++) {</code>

<code>    $seconds = $chunks[$i][0];

$name = $chunks[$i][1];</code>

<code>    // finding the biggest chunk (if the chunk fits, break)

if (($count = floor($since / $seconds)) != 0) {

// DEBUG print "&lt;!-- It's $name --&gt;n";

break;

}

}</code>

<code>$print = ($count == 1) ? '1 '.$name : "$count {$name}s";</code>

<code>if ($i + 1 &lt; $j) {

// now getting the second item

$seconds2 = $chunks[$i + 1][0];

$name2 = $chunks[$i + 1][1];</code>

<code>    // add second item if it's greater than 0

if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {

$print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";

}

}

return $print;

}</code></pre>
<p>I also found a second more compact version from <a href="http://www.byteinsider.com/article/short-and-accurate-time_since-php-function">byteinsider</a> their version (below) takes the input in the form of the MySQL  timestamp format (Y-m-d H:i:s) both functions output the same type of thing tho, so its up to you which you use.<br />
<code> </code></p>
<pre>function time_since($mysql_timestamp)

{

$names =  array('year','month','day','hour','minute','second');$r = time()-strtotime($mysql_timestamp) - date('Z');

$posted = array(date('Y',$r)-1970,date('n',$r)-1,date('d',$r)-1,

 date('G',$r)-0,date('i',$r)-0,date('s',$r)-0);

for($n = 0; $n &lt; 5 &amp;&amp; $posted[$n] == 0; $n++);

$output = $posted[$n].' '.$names[$n];

if($posted[$n] != 1) $output .='s';

if($n &lt; 5 &amp;&amp; $posted[$n+1] != 0)

{

 $output .= ' '.$posted[$n+1].' '.$names[$n+1];

 if($posted[$n+1] != 1) $output .='s';

}

return $output.' ago';

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/php/time_since.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

