<?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; code</title>
	<atom:link href="http://photogabble.co.uk/tag/code/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>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>
		<item>
		<title>PHP Function: Pi</title>
		<link>http://photogabble.co.uk/php/php-function-pi.html</link>
		<comments>http://photogabble.co.uk/php/php-function-pi.html#comments</comments>
		<pubDate>Fri, 11 Aug 2006 08:06:58 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[calculation]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[pi]]></category>

		<guid isPermaLink="false">http://www.photogabble.co.uk/2006/08/11/php-function-pi/</guid>
		<description><![CDATA[Just randomly came up with this after reading about how pi was first discovered and calculated. Im thinking of writing code that calculates pi to many decimals but figuring this out was hard enough lol. &#60;?php Function mypi (){ return (16*(atan(1/5)) - (4*atan(1/239))); } ?&#62; Can be proved true when tested against php&#8217;s own Pi [...]]]></description>
			<content:encoded><![CDATA[<p>Just randomly came up with this after reading about how pi was first discovered and calculated. Im thinking of writing code that calculates pi to many decimals but figuring this out was hard enough lol.</p>
<pre><code>
&lt;?php

Function mypi (){

return (16*(atan(1/5)) - (4*atan(1/239)));

}

?&gt;
</code></pre>
<p>Can be proved true when tested against php&#8217;s own Pi fucntion.</p>
]]></content:encoded>
			<wfw:commentRss>http://photogabble.co.uk/php/php-function-pi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

