<?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>Werx Limited &#187; php</title> <atom:link href="http://werxltd.com/wp/tag/php/feed/" rel="self" type="application/rss+xml" /><link>http://werxltd.com/wp</link> <description>We make IT work.</description> <lastBuildDate>Mon, 07 May 2012 18:40:10 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Check an array for all null values</title><link>http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/</link> <comments>http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/#comments</comments> <pubDate>Mon, 13 Jun 2011 20:38:00 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[php]]></category> <category><![CDATA[software development]]></category> <category><![CDATA[function]]></category> <category><![CDATA[null]]></category> <category><![CDATA[utility]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=978</guid> <description><![CDATA[Here is a simple function to check an array to see if it contains all null values. function allNulls($arr) { if(is_array($arr) &#038;&#038; count(array_diff($arr, array(null))) == 0) { return true; } return false; } echo (allNulls(array(null,null,null)) ? "true" : "false") . PHP_EOL; echo (allNulls(array(null,1,null)) ? "true" : "false") . PHP_EOL; echo (allNulls(array("test",null,null)) ? "true" : "false") [...]]]></description> <content:encoded><![CDATA[<p>Here is a simple function to check an array to see if it contains all null values.</p><pre class="brush:php">
function allNulls($arr) {
    if(is_array($arr) &#038;&#038; count(array_diff($arr, array(null))) == 0) {
            return true;
    }

    return false;
}

echo (allNulls(array(null,null,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array(null,1,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array("test",null,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array("",null,null)) ? "true" : "false") . PHP_EOL;
echo (allNulls(array(0,null,null)) ? "true" : "false") . PHP_EOL;
</pre><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/" data-text="Check an array for all null values"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;linkname=Check%20an%20array%20for%20all%20null%20values" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F06%2F13%2Fcheck-an-array-for-all-null-values%2F&amp;title=Check%20an%20array%20for%20all%20null%20values" id="wpa2a_2">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/06/13/check-an-array-for-all-null-values/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Simple PHP Proxy</title><link>http://werxltd.com/wp/2011/05/24/simple-php-proxy/</link> <comments>http://werxltd.com/wp/2011/05/24/simple-php-proxy/#comments</comments> <pubDate>Tue, 24 May 2011 12:00:17 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[php]]></category> <category><![CDATA[proxy]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=765</guid> <description><![CDATA[While developing apps that use external web services, a proxy often comes in handy in order to bypass the pesky XSS security settings found in most browsers. Here is a simple PHP proxy I&#8217;ve found quite helpful.]]></description> <content:encoded><![CDATA[<p>While developing apps that use external web services, a proxy often comes in handy in order to bypass the pesky XSS security settings found in most browsers. Here is a simple PHP proxy I&#8217;ve found quite helpful.</p><pre class="brush:php">
<?

// http://benalman.com/projects/php-simple-proxy/

$url = "http://mcaf.ee/api/shorten";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_MAXCONNECTS, 16);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_REQUEST));
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);  

if(!is_null($type)) $type = 'text/html';
header('Content-Type: '.$type);

switch($status) {
        case 500:
                header("HTTP/1.1 500 Internal Server Error");
                header("Cache-Control: no-cache");
        break;
        case 200:
        default:
                header("HTTP/1.1 200 OK");
        break;
}

echo $result;
</pre><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2011/05/24/simple-php-proxy/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2011/05/24/simple-php-proxy/" data-text="Simple PHP Proxy"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2011/05/24/simple-php-proxy/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;linkname=Simple%20PHP%20Proxy" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F05%2F24%2Fsimple-php-proxy%2F&amp;title=Simple%20PHP%20Proxy" id="wpa2a_4">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/05/24/simple-php-proxy/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Using PHP to write PHP</title><link>http://werxltd.com/wp/2010/07/29/using-php-to-write-php/</link> <comments>http://werxltd.com/wp/2010/07/29/using-php-to-write-php/#comments</comments> <pubDate>Thu, 29 Jul 2010 19:00:49 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[php]]></category> <category><![CDATA[kml]]></category> <category><![CDATA[mapping]]></category> <category><![CDATA[utilities]]></category> <category><![CDATA[wkt]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=630</guid> <description><![CDATA[I ran into a situation recently where I had a very large array object that was not going to change. It was the polygon coordinates for the world countries to be used in KML provided by Thematic Mapping. I didn&#8217;t wan&#8217;t to pull this data out of MySQL every time I went to build a [...]]]></description> <content:encoded><![CDATA[<p>I ran into a situation recently where I had a very large array object that was not going to change. It was the polygon coordinates for the world countries to be used in <a
href="http://code.google.com/apis/kml/documentation/">KML</a> provided by <a
href="http://thematicmapping.org/">Thematic Mapping</a>.</p><p>I didn&#8217;t wan&#8217;t to pull this data out of MySQL every time I went to build a map, I wanted to use one giant static array instead. So to write the array back out in a re-usable fashion I developed the following code which can take any array, of any depth, associative or index based, and spit out corresponding PHP that you can copy and paste back into your script.</p><pre class="brush:php">function phpPrintArr(array $arr) {
	echo "array(".PHP_EOL;

	$c = 1;
	$total = count($arr);

	foreach($arr as $i =&gt;$v) {
		$iq = is_numeric($i) ? '' : '"';
		$vq = is_numeric($v) ? '' : '"';
		$e = $c &lt; $total ? ',' : '';

		if(is_array($v)) {
			echo $iq.$i.$iq.'=&gt;'.PHP_EOL;
			phpPrintArr($v);
			echo $e.PHP_EOL;
		} else {
			echo $iq.$i.$iq.'=&gt;'.$vq.$v.$vq.$e.PHP_EOL;
		}
		$c++;
	}

	echo ")".PHP_EOL;
}</pre><p>Oh, and for anyone who is interested in the array of country polygons this produced from the Thematic Mapping Engine data, <a
href="http://werxltd.com/software/TME_Countries">here is the rather large array</a>. Feel free to use it in your own KML project.</p><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2010/07/29/using-php-to-write-php/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2010/07/29/using-php-to-write-php/" data-text="Using PHP to write PHP"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2010/07/29/using-php-to-write-php/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F07%2F29%2Fusing-php-to-write-php%2F&amp;linkname=Using%20PHP%20to%20write%20PHP" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F07%2F29%2Fusing-php-to-write-php%2F&amp;title=Using%20PHP%20to%20write%20PHP" id="wpa2a_6">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2010/07/29/using-php-to-write-php/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>HipHop for PHP</title><link>http://werxltd.com/wp/2010/04/29/hiphop-for-php/</link> <comments>http://werxltd.com/wp/2010/04/29/hiphop-for-php/#comments</comments> <pubDate>Thu, 29 Apr 2010 12:00:15 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[c++]]></category> <category><![CDATA[it industry]]></category> <category><![CDATA[php]]></category> <category><![CDATA[software development]]></category> <category><![CDATA[high performance]]></category> <category><![CDATA[hiphop]]></category> <category><![CDATA[web scale]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=573</guid> <description><![CDATA[Earlier this year Facebook developers caused quite a stir in the PHP community by releasing HipHop, the central piece in their high-performance arsenal. Here is the video of the initial announcement along with some juicy technical details: If you are interested in seeing how your PHP project fares when run through HipHop, check out the [...]]]></description> <content:encoded><![CDATA[<p>Earlier this year <a
href="http://developers.facebook.com/blog/post/358">Facebook developers</a> caused quite a stir in the PHP community by releasing <a
href="http://en.wikipedia.org/wiki/HipHop_(software)">HipHop</a>, the central piece in their high-performance arsenal.</p><p><a
href="http://www.ustream.tv/recorded/4409735">Here is the video</a> of the initial announcement along with some juicy technical details:<br
/> <object
id="utv946196" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="386" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param
name="name" value="utv_n_687056" /><param
name="flashvars" value="loc=%2F&amp;autoplay=false&amp;vid=4409735&amp;locale=en_US" /><param
name="allowfullscreen" value="true" /><param
name="allowscriptaccess" value="always" /><param
name="src" value="http://www.ustream.tv/flash/video/4409735" /><embed
id="utv946196" type="application/x-shockwave-flash" width="480" height="386" src="http://www.ustream.tv/flash/video/4409735" allowscriptaccess="always" allowfullscreen="true" flashvars="loc=%2F&amp;autoplay=false&amp;vid=4409735&amp;locale=en_US" name="utv_n_687056"></embed></object></p><p>If you are interested in seeing how your PHP project fares when run through HipHop, check out the official <a
href="http://github.com/facebook/hiphop-php">HipHop project page</a>.</p><p>With tools like HipHop, scripting languages like PHP are no longer subject to the charges of gross computational inefficiency. In short, it&#8217;s a great day to be a web developer.</p><div
class="betterrelated"><p><strong>Related content:</strong></p><ol><li> <a
href="http://werxltd.com/wp/2010/10/12/fred-brooks-on-the-promise-of-object-oriented-programming/" title="Permanent link to Fred Brooks on the promise of object oriented programming">Fred Brooks on the promise of object oriented programming</a></li><li> <a
href="http://werxltd.com/wp/2011/02/28/fun-with-heatmaps/" title="Permanent link to Fun with heatmaps">Fun with heatmaps</a></li></ol><a
class="thanks" style="font-size: smaller; text-decoration: none;" title="Related content found by the Better Related Posts plugin" href="http://www.nkuttler.de/wordpress-plugin/wordpress-related-posts-plugin/">Better Related Posts Plugin</a></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2010/04/29/hiphop-for-php/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2010/04/29/hiphop-for-php/" data-text="HipHop for PHP"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2010/04/29/hiphop-for-php/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F04%2F29%2Fhiphop-for-php%2F&amp;linkname=HipHop%20for%20PHP" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F04%2F29%2Fhiphop-for-php%2F&amp;title=HipHop%20for%20PHP" id="wpa2a_8">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2010/04/29/hiphop-for-php/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>SOAPjr Demo</title><link>http://werxltd.com/wp/2009/10/17/soapjr-demo/</link> <comments>http://werxltd.com/wp/2009/10/17/soapjr-demo/#comments</comments> <pubDate>Sat, 17 Oct 2009 13:36:33 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[software development]]></category> <category><![CDATA[extjs]]></category> <category><![CDATA[php]]></category> <category><![CDATA[soapjr]]></category> <category><![CDATA[symfony]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=230</guid> <description><![CDATA[A demo of SOAPjr using PHP/Symfony and ExtJS is now available at http://dev.communitybookshelf.org/ This demo showcases these custom components: Backend: pSOAPjr sfSOAPjrActionPlugin Frontend eSOAPjr Questions/comments? We&#8217;d love to hear from you! No related content found.]]></description> <content:encoded><![CDATA[<p>A demo of <a
href="http://soapjr.org/">SOAPjr</a> using <a
href="http://php.net/">PHP</a>/<a
href="http://www.symfony-project.org/">Symfony</a> and <a
href="http://www.extjs.com/">ExtJS</a> is now available at <a
href="http://dev.communitybookshelf.org/">http://dev.communitybookshelf.org/</a></p><p>This demo showcases these custom components:</p><ul><li>Backend:<ul><li><a
href="http://werxltd.com/wp/portfolio/psoapjr/">pSOAPjr</a></li><li><a
href="http://werxltd.com/wp/portfolio/sfsoapjractionplugin/">sfSOAPjrActionPlugin</a></li></ul></li><li>Frontend<ul><li><a
href="http://werxltd.com/wp/portfolio/esoapjr/">eSOAPjr</a></li></ul></li></ul><p><a
href="http://werxltd.com/wp/contact-us/">Questions/comments? We&#8217;d love to hear from you!</a></p><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2009/10/17/soapjr-demo/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2009/10/17/soapjr-demo/" data-text="SOAPjr Demo"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2009/10/17/soapjr-demo/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F10%2F17%2Fsoapjr-demo%2F&amp;linkname=SOAPjr%20Demo" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F10%2F17%2Fsoapjr-demo%2F&amp;title=SOAPjr%20Demo" id="wpa2a_10">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2009/10/17/soapjr-demo/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Running PHP in Java</title><link>http://werxltd.com/wp/2009/10/06/running-php-in-java/</link> <comments>http://werxltd.com/wp/2009/10/06/running-php-in-java/#comments</comments> <pubDate>Tue, 06 Oct 2009 21:25:54 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[software development]]></category> <category><![CDATA[cloud computing]]></category> <category><![CDATA[drupal]]></category> <category><![CDATA[high availability]]></category> <category><![CDATA[java]]></category> <category><![CDATA[php]]></category> <category><![CDATA[php in the cloud]]></category> <category><![CDATA[wordpress]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=227</guid> <description><![CDATA[Many might consider even the thought of running PHP inside of a Java Virtual Machine to be anathema. Others will wonder why bother (apart from the novelty). However running PHP in Java has one crucal benefit: it future-proofs your code. Quercus is a nifty utility that will allow you to run PHP code in clouds such [...]]]></description> <content:encoded><![CDATA[<p>Many might consider even the thought of running <a
href="http://www.php.net/">PHP</a> inside of a <a
href="http://en.wikipedia.org/wiki/Java_Virtual_Machine">Java Virtual Machine</a> to be anathema. Others will wonder why bother (apart from the novelty). However running PHP in Java has one crucal benefit: it future-proofs your code.</p><p><a
href="http://caucho.com/resin/doc/quercus.xtp">Quercus</a> is a nifty utility that will allow you to run PHP code in clouds such as <a
href="http://blog.caucho.com/?p=187">Google App Engine</a><sup><a
href="http://werxltd.com/wp/2009/10/06/running-php-in-java/#footnote_0_227" id="identifier_0_227" class="footnote-link footnote-identifier-link" title="Other great articles on running PHP in Google&amp;#8217;s App Engine can be found here and here. IBM has also highlighted this utility.">1</a></sup>. This means your <a
href="http://drupal.org/">Drupal</a> and <a
href="http://wordpress.org/">WordPress</a> sites can now be distributed across a highly avaliable and scalable cloud infrustructure.</p><p>Now if we can only get an <a
href="http://en.wikipedia.org/wiki/Model–view–controller">MVC</a> framework like <a
href="http://kohanaphp.com/">Kohana</a> or <a
href="http://www.symfony-project.org/">Symfony</a> to work on top of this system..</p><div
class="betterrelated none"><p>No related content found.</p></div><ol
class="footnotes"><li
id="footnote_0_227" class="footnote">Other great articles on running PHP in Google&#8217;s App Engine can be found <a
href="http://www.phpclasses.org/blog/post/92-Running-PHP-on-Google-App-Engine.html">here</a> and <a
href="http://www.webdigi.co.uk/blog/2009/run-php-on-the-google-app-engine/">here</a>. <a
href="http://www.ibm.com/developerworks/web/library/wa-quercus/index.html?ca=dgr-twtrQuercusdth-WD&amp;S_TACT=105AGY46&amp;S_CMP=TWDW">IBM has also highlighted</a> this utility.</li></ol><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2009/10/06/running-php-in-java/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2009/10/06/running-php-in-java/" data-text="Running PHP in Java"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2009/10/06/running-php-in-java/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F10%2F06%2Frunning-php-in-java%2F&amp;linkname=Running%20PHP%20in%20Java" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F10%2F06%2Frunning-php-in-java%2F&amp;title=Running%20PHP%20in%20Java" id="wpa2a_12">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2009/10/06/running-php-in-java/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Magical PHP JSON Object Cleaner</title><link>http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/</link> <comments>http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/#comments</comments> <pubDate>Wed, 29 Jul 2009 14:27:03 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[software development]]></category> <category><![CDATA[json]]></category> <category><![CDATA[optimization]]></category> <category><![CDATA[php]]></category> <category><![CDATA[recursive]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=159</guid> <description><![CDATA[I wrote this method the other day that takes a simple PHP object, inspects it&#8217;s properties and &#8220;prunes&#8221; empty ones. I wrote this method in order to compress JSON objects by removing null properties before sending them down the wire, a big problem when using base objects or models. If you find this useful or [...]]]></description> <content:encoded><![CDATA[<p>I wrote this method the other day that takes a simple PHP object, inspects it&#8217;s properties and &#8220;prunes&#8221; empty ones. I wrote this method in order to compress JSON objects by removing null properties before sending them down the wire, a big problem when using base objects or models.</p><p>If you find this useful or a have a suggestion, feel free to let me know!</p><pre class="brush:php">
private function getStripped($obj) {
		$objVars = get_object_vars($obj);

		if(count($objVars) > 0) {
			foreach($objVars as $propName => $propVal) {
				if(gettype($propVal) == "object") {
					$cObj = $this->getStripped($propVal);
					if($cObj == null) {
						unset($obj->$propName);
					} else {
						$obj->$propName = $cObj;
					}
				} else {
					if(empty($propVal)) {
						unset($obj->$propName);
					}
				}
			}
		} else {
			return null;
		}
		return $obj;
	}</pre><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/" data-text="Magical PHP JSON Object Cleaner"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F07%2F29%2Fmagical-php-json-object-cleaner%2F&amp;linkname=Magical%20PHP%20JSON%20Object%20Cleaner" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F07%2F29%2Fmagical-php-json-object-cleaner%2F&amp;title=Magical%20PHP%20JSON%20Object%20Cleaner" id="wpa2a_14">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc
Database Caching 2/34 queries in 0.010 seconds using apc
Object Caching 793/867 objects using apc

Served from: werxltd.com @ 2012-05-21 19:44:54 -->
