<?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>Graphic Maniacs &#187; PHP</title>
	<atom:link href="http://graphicmaniacs.com/cat/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://graphicmaniacs.com</link>
	<description></description>
	<lastBuildDate>Wed, 18 Jan 2012 13:08:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting a list of WordPress hook actions</title>
		<link>http://graphicmaniacs.com/note/getting-a-list-of-wordpress-hook-actions/</link>
		<comments>http://graphicmaniacs.com/note/getting-a-list-of-wordpress-hook-actions/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 13:08:40 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=907</guid>
		<description><![CDATA[Sometimes content is outputted somewhere where I don&#8217;t need (when I run do_action), and I can&#8217;t really see what action does that. So to get the list of WordPress actions attached to a hook, use this kind of code: global $wp_filter; var_dump&#40;$wp_filter&#91;'comment_form'&#93;&#41;; You will get then something like this: array&#40;1&#41; &#123; &#91;10&#93;=&#62; array&#40;2&#41; &#123; &#91;&#34;wp_comment_form_unfiltered_html_nonce&#34;&#93;=&#62; [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/getting-a-list-of-wordpress-hook-actions/' addthis:title='Getting a list of WordPress hook actions '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Sometimes content is outputted somewhere where I don&#8217;t need (when I run <strong>do_action</strong>), and I can&#8217;t really see what action does that. So to get the list of WordPress actions attached to a hook, use this kind of code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_filter</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_filter</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'comment_form'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You will get then something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;wp_comment_form_unfiltered_html_nonce&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;function&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
      string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">37</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;wp_comment_form_unfiltered_html_nonce&quot;</span>
      <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;accepted_args&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
      int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;akismet_add_comment_nonce&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;function&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
      string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;akismet_add_comment_nonce&quot;</span>
      <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;accepted_args&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
      int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Pretty cool, now we know what produces all that output.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/getting-a-list-of-wordpress-hook-actions/' addthis:title='Getting a list of WordPress hook actions '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/getting-a-list-of-wordpress-hook-actions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issue with Flash uploader and Suhosin PHP patch</title>
		<link>http://graphicmaniacs.com/note/issue-with-flash-uploader-and-suhosin-php-patch/</link>
		<comments>http://graphicmaniacs.com/note/issue-with-flash-uploader-and-suhosin-php-patch/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 10:36:54 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=892</guid>
		<description><![CDATA[This is a very simply situation: we use multiple files Flash uploader to display progress, and for other extended functionality when uploading files. But this issue was killing me. After installing Suhosin patch, the session was breaking after any file upload. This was made because Suhosin checks the User-Agent also, and Flash has a different [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/issue-with-flash-uploader-and-suhosin-php-patch/' addthis:title='Issue with Flash uploader and Suhosin PHP patch '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>This is a very simply situation: we use multiple files Flash uploader to display progress, and for other extended functionality when uploading files. But this issue was killing me. After installing Suhosin patch, the session was breaking after any file upload.</p>
<p>This was made because <strong>Suhosin checks the User-Agent</strong> also, and Flash has a different user agent from the browser. Even providing a session id to Flash won&#8217;t solve the issue because Suhosin checks the user agents when session_id/session_start is called.</p>
<p>To solve this issue, simply disable user agent encrypting, but leave the IP address encrypting in php.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">suhosin<span style="color: #339933;">.</span>session<span style="color: #339933;">.</span>encrypt <span style="color: #339933;">=</span> On
suhosin<span style="color: #339933;">.</span>session<span style="color: #339933;">.</span>cryptraddr <span style="color: #339933;">=</span> On
suhosin<span style="color: #339933;">.</span>session<span style="color: #339933;">.</span>cryptua <span style="color: #339933;">=</span> Off</pre></div></div>

<h4>This page can be found by searching for:</h4><div class='search-terms'><span>flash suhosin</span><span>deactivate suhosin</span><span>flash uploader php</span><span>suhosin session encrypt flash</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/issue-with-flash-uploader-and-suhosin-php-patch/' addthis:title='Issue with Flash uploader and Suhosin PHP patch '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/issue-with-flash-uploader-and-suhosin-php-patch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to remove &#8220;on behalf of&#8221; in PHP mail for Outlook 2007 and 2010</title>
		<link>http://graphicmaniacs.com/note/how-to-remove-on-behalf-of-in-php-mail-for-outlook-2007-and-2010/</link>
		<comments>http://graphicmaniacs.com/note/how-to-remove-on-behalf-of-in-php-mail-for-outlook-2007-and-2010/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 08:00:16 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=846</guid>
		<description><![CDATA[Anyone noticed that stupid &#8220;admin@domain.com; on behalf of; noreply@domain.com&#8221; bug in subject when you received email with Outlook 2007 and 2010? Well, the fix is pretty simple. While we were setting the From: &#60;email@domain.com&#62; header, now we need to set the Sender header too. So it looks like: $header=''; $header.=&#34;Sender: $from\r\n&#34;; $header.=&#34;From: $from\r\n&#34;; $header.=&#34;MIME-Version: 1.0\r\n&#34;; [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/how-to-remove-on-behalf-of-in-php-mail-for-outlook-2007-and-2010/' addthis:title='How to remove &#8220;on behalf of&#8221; in PHP mail for Outlook 2007 and 2010 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Anyone noticed that stupid &#8220;<strong>admin@domain.com; on behalf of; noreply@domain.com</strong>&#8221; bug in subject when you received email with Outlook 2007 and 2010?</p>
<p>Well, the fix is pretty simple. While we were setting the <strong>From: &lt;email@domain.com&gt;</strong> header, now we need to set the Sender header too. So it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;Sender: <span style="color: #006699; font-weight: bold;">$from</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;From: <span style="color: #006699; font-weight: bold;">$from</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;Content-Type: text/html; charset=utf-8<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;Content-Transfer-Encoding: 8bit<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'=?UTF-8?B?'</span><span style="color: #339933;">.</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subject</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?='</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s it. It took me a while googling for the issue to find it, but hopefully it saves your day!</p>
<h4>This page can be found by searching for:</h4><div class='search-terms'><span>remove on behalf of outlook</span><span>php mail outlook 2010</span><span>disable skype email in php</span><span>removing on behalf of in email php</span><span>remove on behalf of outlook 2010</span><span>remove google on behalf of</span><span>php mail outlook 2007</span><span>php mail on behalf of</span><span>php mail from email without on behalf of</span><span>php mail correct headers for outlook 2010</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/how-to-remove-on-behalf-of-in-php-mail-for-outlook-2007-and-2010/' addthis:title='How to remove &#8220;on behalf of&#8221; in PHP mail for Outlook 2007 and 2010 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/how-to-remove-on-behalf-of-in-php-mail-for-outlook-2007-and-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check if ZIP file is valid with PHP</title>
		<link>http://graphicmaniacs.com/note/check-if-zip-file-is-valid-with-php/</link>
		<comments>http://graphicmaniacs.com/note/check-if-zip-file-is-valid-with-php/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 15:53:16 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=834</guid>
		<description><![CDATA[Recently, i tried to check if ZIP file is valid by checking its MIME type. But server to server, it varies and sometimes even shows up like application/unknown. This is bad, so let&#8217;s just rely on native PHP functions: function zipIsValid&#40;$path&#41; &#123; $zip = zip_open&#40;$path&#41;; if &#40;is_resource&#40;$zip&#41;&#41; &#123; // it's ok zip_close&#40;$zip&#41;; // always close [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/check-if-zip-file-is-valid-with-php/' addthis:title='Check if ZIP file is valid with PHP '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Recently, i tried to check if ZIP file is valid by checking its MIME type. But server to server, it varies and sometimes even shows up like <strong>application/unknown</strong>. This is bad, so let&#8217;s just rely on native PHP functions:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> zipIsValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$zip</span> <span style="color: #339933;">=</span> <span style="color: #990000;">zip_open</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_resource</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// it's ok</span>
    <span style="color: #990000;">zip_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// always close handle if you were just checking</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>zipIsValid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myzip.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// do stuff</span>
  <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>zip_open will return a resource in case of successful opening, otherwise it will return an integer with error code, so checking for <strong>if ($zip)</strong> won&#8217;t be proper.</p>
<h4>This page can be found by searching for:</h4><div class='search-terms'><span>php check if is zipped</span><span>php check if zip</span><span>php check if zip file</span><span>how to check valid zip file in php</span><span>php check if valid zip file</span><span>php check if zip file is valid</span><span>php check if zip is correct</span><span>php check is zip file</span><span>php check valid zip</span><span>php check validate rss 2 0</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/check-if-zip-file-is-valid-with-php/' addthis:title='Check if ZIP file is valid with PHP '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/check-if-zip-file-is-valid-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook-like time ago with PHP</title>
		<link>http://graphicmaniacs.com/note/facebook-like-time-ago-with-php/</link>
		<comments>http://graphicmaniacs.com/note/facebook-like-time-ago-with-php/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 10:34:24 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=773</guid>
		<description><![CDATA[Ever wanted to have your date display like Facebook has? &#8220;3 minutes ago&#8221; instead of &#8220;09:12:10&#8243;? Well, here&#8217;s a very simple code with PHP: function ago&#40;$time&#41; &#123; $periods = array&#40;&#34;second&#34;, &#34;minute&#34;, &#34;hour&#34;, &#34;day&#34;, &#34;week&#34;, &#34;month&#34;, &#34;year&#34;, &#34;decade&#34;&#41;; $lengths = array&#40;&#34;60&#34;,&#34;60&#34;,&#34;24&#34;,&#34;7&#34;,&#34;4.35&#34;,&#34;12&#34;,&#34;10&#34;&#41;; &#160; $now = time&#40;&#41;; &#160; $difference = $now - $time; if &#40;$difference &#62; 0&#41; $tense [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/facebook-like-time-ago-with-php/' addthis:title='Facebook-like time ago with PHP '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to have your date display like Facebook has? &#8220;3 minutes ago&#8221; instead of &#8220;09:12:10&#8243;?</p>
<p>Well, here&#8217;s a very simple code with PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> ago<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$periods</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;second&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;minute&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;hour&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;day&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;week&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;month&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;decade&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$lengths</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;60&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;60&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;24&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;7&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;4.35&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;12&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$now</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$now</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$difference</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000088;">$tense</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ago'</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">else</span>
      <span style="color: #000088;">$tense</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'in future'</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$difference</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$lengths</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lengths</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$difference</span> <span style="color: #339933;">/=</span> <span style="color: #000088;">$lengths</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$difference</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$difference</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$periods</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$difference</span> <span style="color: #006699; font-weight: bold;">$periods</span>[<span style="color: #006699; font-weight: bold;">$j</span>] <span style="color: #006699; font-weight: bold;">$tense</span> &quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;I was here &quot;</span><span style="color: #339933;">.</span>ago<span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// will output &quot;I was here 1 hour ago&quot;</span></pre></div></div>

<p>Another way is to use a function from <a href="http://www.php.net/manual/en/function.time.php#91864" target="_blank" rel="nofollow">andypsv</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> time_ago<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tm</span><span style="color: #339933;">,</span><span style="color: #000088;">$rcs</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cur_tm</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$dif</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cur_tm</span><span style="color: #339933;">-</span><span style="color: #000088;">$tm</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$pds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'second'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'minute'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'hour'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'day'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'week'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'month'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'year'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'decade'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$lngh</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">86400</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">604800</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2630880</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">31570560</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">315705600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lngh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$no</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dif</span><span style="color: #339933;">/</span><span style="color: #000088;">$lngh</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$v</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$_tm</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cur_tm</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dif</span><span style="color: #339933;">%</span><span style="color: #000088;">$lngh</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$no</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$no</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$no</span> <span style="color: #339933;">&lt;&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$pds</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">'s'</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%d</span> <span style="color: #009933; font-weight: bold;">%s</span> &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$no</span><span style="color: #339933;">,</span><span style="color: #000088;">$pds</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rcs</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cur_tm</span><span style="color: #339933;">-</span><span style="color: #000088;">$_tm</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">.=</span> time_ago<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_tm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$x</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hope you found it handy, I did.</p>
<h4>This page can be found by searching for:</h4><div class='search-terms'><span>php facebook time ago</span><span>php facebook like time</span><span>php time ago</span><span>facebook like time php</span><span>time ago php</span><span>graphic maniacs note facebook like time ago php</span><span>code for facebook comment and time ago using jquery</span><span>jquery time ago facebook</span><span>php time ago like facebook</span><span>php time ago function</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/facebook-like-time-ago-with-php/' addthis:title='Facebook-like time ago with PHP '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/facebook-like-time-ago-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

