<?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>Sjoerd Maessen blog</title>
	<atom:link href="http://www.sjoerdmaessen.be/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sjoerdmaessen.be</link>
	<description>PHP and webdevelopment</description>
	<lastBuildDate>Mon, 09 Aug 2010 11:19:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Separating your controller from your view</title>
		<link>http://www.sjoerdmaessen.be/2010/08/09/separating-your-controller-from-your-view/</link>
		<comments>http://www.sjoerdmaessen.be/2010/08/09/separating-your-controller-from-your-view/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 11:08:05 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[syntax]]></category>
		<category><![CDATA[application structure]]></category>
		<category><![CDATA[business logic]]></category>
		<category><![CDATA[presentation logic]]></category>
		<category><![CDATA[three tier]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=272</guid>
		<description><![CDATA[What is a controller? A controller can best be described as the set of instructions and algorithms that are responsible for making your application actually doing something. Often based on user input. You could say your controller is your business logic. What is a view? The view is the presentation of your application, the part [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What is a controller?</strong><br />
A controller can best be described as the set of instructions and algorithms that are responsible for making your application actually doing something. Often based on user input. You could say your controller is your business logic.</p>
<p><strong>What is a view?</strong><br />
The view is the presentation of your application, the part that our user sees. The view won&#8217;t do any processing (like math, checking data,&#8230;) it will just show data.</p>
<p><strong>Why don&#8217;t you separate your logic and view?</strong><br />
I don&#8217;t know how or I don&#8217;t use a framework. Those are both often heard excuses when I ask someone why he doesn&#8217;t separate the logic and view of his application. Even when you <span id="more-272"></span>don&#8217;t use a framework your can perfectly separate your logic from your view. </p>
<p>Consider the following example that is based on a real-life application. Don&#8217;t mind the code just watch what a difference it makes when you separate your logic and presentation.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;html&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;head&gt;&lt;title&gt;Website: blocked&lt;/title&gt;&lt;/head&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;body&gt;</div>
</li>
<li class="li2">
<div class="de2">&lt;h1&gt;Dear visitor&lt;/h1&gt;,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">&lt;?</span> <span class="re0">$getR</span> = <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;SELECT Block_name,Block_type,Block_datum FROM blocks WHERE Block_id={$_blockID}&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; &nbsp;<span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&lt;p&gt;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?</span>=datum<span class="br0">&#40;</span><span class="st0">&quot;d F Y&quot;</span>,<span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&quot;Block_datum&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;?&gt;:</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&quot;Block_type&quot;</span><span class="br0">&#93;</span> == <span class="st0">&quot;ip&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$val</span> = <span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&#8216;Block_name&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot; page is blocked by ip &lt;b&gt;{$val}&lt;/b&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&quot;Block_type&quot;</span><span class="br0">&#93;</span> == <span class="st0">&quot;player&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$player</span>= getPlayer<span class="br0">&#40;</span><span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&quot;Block_name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$val</span> = <span class="re0">$player</span><span class="br0">&#91;</span><span class="st0">&#8216;fullName&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot; is blocked for player&lt;b&gt;{$val}&lt;/b&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&quot;Block_type&quot;</span><span class="br0">&#93;</span> == <span class="st0">&quot;team&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$team</span> = getTeam<span class="br0">&#40;</span><span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&quot;Block_name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$val</span> = <span class="re0">$team</span><span class="br0">&#91;</span><span class="st0">&#8216;name&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot; is blocked for team &lt;b&gt;{$val}&lt;/b&gt;.&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&lt;/body&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/html&gt;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>
And now lets look at the same piece of code again but then refactored:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$mResult</span> = <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;SELECT Block_name,Block_type,Block_datum FROM blocks WHERE Block_id=&#8217;&quot;</span>.<span class="re0">$iblockID</span>.<span class="st0">&quot;&#8217;&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$aResult</span> = <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$mResult</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Determine the error message</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$sReplaceValue</span> = <span class="st0">&#8221;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$sErrorMessage</span> = <span class="st0">&#8216;Unknown error&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">switch</span><span class="br0">&#40;</span><span class="re0">$aResult</span><span class="br0">&#91;</span><span class="st0">&quot;Block_type&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#8216;ip&#8217;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sReplaceValue</span> = <span class="re0">$aResult</span><span class="br0">&#91;</span><span class="st0">&#8216;Block_name&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sErrorMessage</span> = <span class="st0">&quot; page is blocked by ip &lt;b&gt;%s&lt;/b&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#8216;player&#8217;</span>:</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$aPlayer</span>= getPlayer<span class="br0">&#40;</span><span class="re0">$getR</span><span class="br0">&#91;</span><span class="st0">&quot;Block_name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sReplaceValue</span> = <span class="re0">$aPlayer</span><span class="br0">&#91;</span><span class="st0">&#8216;name&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sErrorMessage</span> = <span class="st0">&quot; is blocked for player &lt;b&gt;%s&lt;/b&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#8216;team&#8217;</span>:</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$aTeam</span> = getTeam<span class="br0">&#40;</span><span class="re0">$aResult</span><span class="br0">&#91;</span><span class="st0">&#8216;Block_name&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sReplaceValue</span> = <span class="re0">$aTeam</span><span class="br0">&#91;</span><span class="st0">&#8216;name&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sErrorMessage</span> = <span class="st0">&quot; is blocked for team &lt;b&gt;%s&lt;/b&gt;.&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$sErrorMessage</span> = <a href="http://www.php.net/sprintf"><span class="kw3">sprintf</span></a><span class="br0">&#40;</span><span class="re0">$sErrorMessage</span>, <span class="re0">$sReplaceValue</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$sDate</span> = <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;d F Y&quot;</span>, <span class="re0">$aResult</span><span class="br0">&#91;</span><span class="st0">&quot;Block_datum&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&lt;html&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;head&gt;&lt;title&gt;Website: blocked&lt;/title&gt;&lt;/head&gt;</div>
</li>
<li class="li2">
<div class="de2">&lt;body&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;h1&gt;Dear visitor&lt;/h1&gt;,</div>
</li>
<li class="li1">
<div class="de1">&lt;p&gt;&lt;?php <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$sDate</span>;?&gt;:<span class="kw2">&lt;?php</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$sErrorMessage</span>;?&gt;&lt;/p&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/body&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/html&gt;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>The second code is much easier to read and maintain the first one, with just a minimal of effort. Lets take it a step futher.</p>
<p><strong>Application structures, multitier architecture</strong></p>
<p><em>A three tier application</em><br />
<br />One of the simplest architectures is the three tier structure. This architecture is commonly used in applications. (also take a look at MVC)</p>
<table style="border:1px solid #ccc; margin-bottom:25px;">
<tr>
<td style="border:1px solid #ccc;">Database</td>
</tr>
<tr>
<td style="border:1px solid #ccc;">Business logic / controller</td>
</tr>
<tr>
<td style="border:1px solid #ccc;">Presentation / view</td>
</tr>
</table>
<p><em>A four layer application</em><br />
Often a fourth layer is added, the domain layer. By adding a domain layer we have a distinct between our business logic and the data access layer (mostly a database).</p>
<table style="border:1px solid #ccc; margin-bottom:25px;">
<tr>
<td style="border:1px solid #ccc;">Database</td>
</tr>
<tr>
<td style="border:1px solid #ccc;">Domain</td>
</tr>
<tr >
<td style="border:1px solid #ccc;">Business logic / controller</td>
</tr>
<tr>
<td style="border:1px solid #ccc;">Presentation / view</p>
</td>
</tr>
</table>
<p><strong>Why do we need to separate them?</strong><br />
There are a lot of advantages when you separate your business logic from your presentation logic. </p>
<ul>
<li>the code will be easier to maintain.</li>
<li>the logic will be easier to read and understand because it is not mixed with presentation code.</li>
<li>It is easier to reuse code if the presentation is not mixed. The layout of a application will almost always be different when writing a new application but the logic behind it can be exactly the same.</li>
<li>by using different layers in your application each layer can be developed by another team simultaneously.</li>
<li>you will be able to completely change the domain layer to retrieve data from another source then the database without touching the other layers in your application.</li>
</ul>
<p></p>
<p><strong>Conclusion</strong><br />
So even if you don&#8217;t use a framework it should be no problem to separate logic and presentation. It isn&#8217;t about which framework or structure you use, just use someting that brings some kind of organisation in your applications.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/08/09/separating-your-controller-from-your-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ImageMagick installing and exploring it, a good alternative for the GD library</title>
		<link>http://www.sjoerdmaessen.be/2010/07/19/the-first-steps-with-imagemagick-installing-and-exploring-it-a-good-alternative-for-the-gd-library/</link>
		<comments>http://www.sjoerdmaessen.be/2010/07/19/the-first-steps-with-imagemagick-installing-and-exploring-it-a-good-alternative-for-the-gd-library/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 06:20:47 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[GD library]]></category>
		<category><![CDATA[ImageMagick]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=233</guid>
		<description><![CDATA[Although PHP GD library handles basic image operations quite good, you have probably run into the limitations of GD library as well, it is often slow, memory intensive and a bit complicated to use for advanced image effects. ImageMagick however is a very good alternative. It is an opensource software suite licensed under a BSD [...]]]></description>
			<content:encoded><![CDATA[<p>Although PHP GD library handles basic image operations quite good, you have probably run into the limitations of GD library as well, it is often slow, memory intensive and a bit complicated to use for advanced image effects. ImageMagick however is a very good alternative. It is an opensource software suite licensed under a <a target="_blank" href="http://en.wikipedia.org/wiki/BSD_licenses">BSD style license</a> from IM itself. ImageMagick provides in all functionality that can be accomplished with the GD library but even goes a step further with support for more advanced image edit techniques. An example of such a technique is the recently added &#8220;liquid scaling&#8221; feature, this is a content aware scaling option. <span id="more-233"></span></p>
<p>Click the image below to see an example of liquid scaling:<br />
<a border="0" target="_blank" href="http://www.sjoerdmaessen.be/wp-content/uploads/animate_lqr.gif"><img src="http://www.sjoerdmaessen.be/wp-content/uploads/animate_lqr-150x150.gif" alt="Liquid Scaling with imagemagick" title="animate_lqr" width="150" height="150" class="alignnone size-thumbnail wp-image-243" /></a></p>
<p>So how do I get such a result? Well with PHP GD library it would take a whole lot of code, thinking and beers to get a script that does the same without exceeding your memory_limit, with ImageMagick however it is just one simple command.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/exec"><span class="kw3">exec</span></a><span class="br0">&#40;</span><span class="st0">&quot;convert inputimage.jpg &nbsp;-liquid-rescale 250&#215;500%<span class="es0">\!</span> &nbsp;outputimage.jpg&quot;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>The nice thing about ImageMagick is that you can often accomplish very sophisticated image effects with just one command, you can also chain commands. Now although IM has a quite good documentation guide available you maybe just want to be able to perform basic image operations with IM without seeking your way trough the documentation all the time. Their are some PHP classes available that will make your life easier. </p>
<ul>
<li><a traget="_blank" href="http://www.francodacosta.com/blog/phmagick">PhMagick</a> is a simple wrapper class and provides a set of methods to perform the mostly used image operations</li>
<li><a target="_blank" href="http://www.magickwand.org/">MagickWand</a> is a PHP extension that allows to communicate with the IM api</li>
<li><a target="_blank" href="http://pecl.php.net/package/imagick">Imagick is also an extension</a>
</ul>
<p>My personal favor is PhMagick or a home brew script, why? Well I like the idea of wrapper classes more, my code is somewhat more portable because I don&#8217;t have to install the IM extension on a server and another PHP extension to communicate with it, furthermore I think that using wrapper classes gives you more insight in IM itself, you will better understand what is going on, on the other hand you probably will spend some hours to figure out why the command is not doing what you expected it to do because you are missing a simple ! or ^ parameter option.</p>
<p><strong>Personal experience on installing IM on the server</strong><br />
Some time ago I wanted to install IM on my new dev and live server, the dev server is running OSX and the live server is running a Fedora distribution. So the first step before I tried to install IM was to read the documentation (yeah I&#8217;m one of those guys that also actually reads the readme files and documentation <img src='http://www.sjoerdmaessen.be/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  of products). I followed the &#8220;<a target="_blank" href="http://www.imagemagick.org/script/install-source.php">Install from source</a>&#8221; tutorial. So I started with the live server, after downloading and unpacking IM I ran the ./configure command immediately I was faced with the error &#8220;no acceptable c compiler found in $PATH&#8221;, now my Linux skills are far from topnotch, so after some googling I found out that the easiest way to fix this issue was to install <a target="_blank" href="http://gcc.gnu.org/">GCC</a> (GNU Compiler Collection) that already included a C compiler. After installing GCC and running the ./configure command everything went fine, IM was installed successfully. I wanted to test if it was working correctly so I tried to resize several images but again an error occurred &#8220;convert: no decode delegate for this image format&#8221;, okay perhaps I should read the documentation more carefully next time because before installing IM you should also install the image libraries that you will use. In my case this was &#8220;yum install libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel&#8221;, now again I needed to install IM again, not much work, but still something to remember when installing IM. On the dev OSX server installing ImageMagick was quite simple, I used a precompiled dmg and only needed to install the Apple XCode developer tools.</p>
<p><strong>So to summarize:</strong></p>
<p><strong>Advantages of using ImageMagick:</strong></p>
<ul>
<li>it uses less resources, forget about the memory_limit issues with PHP when using GD and large images</li>
<li>it&#8217;s slighty faster (note: depending on the filetype and image size GD beats IM in speed when it comes to resizing</li>
<li>Image Magick has support for more filetypes</li>
<li>as I showed before, it is very simple to use 
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/exec"><span class="kw3">exec</span></a><span class="br0">&#40;</span><span class="st0">&#8216;convert &quot;&#8217;</span>.<span class="re0">$sSourcePath</span>.<span class="st0">&#8216;&quot; -resize &#8216;</span>.<span class="re0">$iWidth</span>.<span class="st0">&#8216;x&quot;&#8217;</span>.<span class="re0">$sDestinationPath</span>.<span class="st0">&#8216;&quot;&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
</li>
<li>Some very nice features like liquid scaling or <a rel="external" href="http://en.wikipedia.org/wiki/Seam_carving">seam carving</a></li>
</ul>
<p><strong>Disadvantages of using Image Magick:</strong></p>
<ul>
<li>you need to have full access to your server, it isn&#8217;t bundled with PHP</li>
<li>compiling IM can give some trouble, you shouldn&#8217;t forget to get the image libraries  you want to use</li>
</ul>
<p></strong></p>
<p><strong>Useful links</strong></p>
<ul>
<li><a target="_blank" href="http://www.imagemagick.org/script/index.php">ImageMagick website</a></li>
<li><a target="_blank" href="http://www.imagemagick.org/Usage/">ImageMagick examples</a></li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/07/19/the-first-steps-with-imagemagick-installing-and-exploring-it-a-good-alternative-for-the-gd-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git tutorial, getting started with Git</title>
		<link>http://www.sjoerdmaessen.be/2010/06/14/git-tutorial-getting-started-with-git/</link>
		<comments>http://www.sjoerdmaessen.be/2010/06/14/git-tutorial-getting-started-with-git/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 06:23:13 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=206</guid>
		<description><![CDATA[Below is a short comprehensive description of getting Git up and running in just a few minutes. I personally use OSX as a development machine and so the installation part of Git will cover an installation on OSX. If you like to install Git on another platform please take a look at the Git installation [...]]]></description>
			<content:encoded><![CDATA[<p>Below is a short comprehensive description of getting Git up and running in just a few minutes. I personally use OSX as a development machine and so the installation part of Git will cover an installation on OSX. If you like to install Git on another platform please take a look at the <a href="http://book.git-scm.com/2_installing_git.html" target="_blank">Git installation documentation</a>. There are a lot of other ways to install Git, but the one described below  seems to bring the least hassle on OSX.<br />
<span id="more-206"></span><br />
<strong>Install Git and add your first project</strong></p>
<ul>
<li>First download the installer at the Google Git OSX installer project, <a href="http://code.google.com/p/git-osx-installer/downloads/list" target="_blank">http://code.google.com/p/git-osx-installer/downloads/list</a> after running the installer you are good to go.</li>
<li>After this easy GUI installation it&#8217;s time to startup the terminal, although if you really are into GUI&#8217;s you can also download and install OpenInGitGui which can be found at <a href="http://code.google.com/p/git-osx-installer/wiki/OpenInGitGui" target="_blank">http://code.google.com/p/git-osx-installer/wiki/OpenInGitGui</a>. In your terminal go to the directory where your website is located and initialize a new repository here.<br />
<code><br />
$cd site_directory<br />
$git init<br />
</code><br />
You should now get a response like &#8220;Initialized empty Git repository in site_directory/.git/&#8221;. The next step is to add the current directory and all of its contents to the repository.<br />
<code><br />
$git add .<br />
$git commit -m "Initial import"<br />
</code><br />
You will now see that all files and directories are committed.</li>
</ul>
<p>Basically this is it, nothing more to it. You could now start working with Git. Off course we can configure the Git installation just a little bit to set things right.</p>
<p><strong>Basic configuration of Git, ignoring files and configuring the user settings</strong><br />
Whenever you will type &#8220;git status&#8221; on the current directory you will see if there are any changes that need to be committed, if so you can add them with the &#8220;commit&#8221; command like we did before. One of the first problems that you will bump into is that your cache files will also be committed. I personally don&#8217;t want to commit automatically created cache files or user content. So how can we deal with this? We can create a &#8220;.gitignore&#8221; file in the root of our project. You can find an example of the .gitignore file below.<br />
<code><br />
*.cache<br />
files<br />
</code><br />
Now any file that has the *.cache extension will be ignored, also all the user content in the files directory will be ignored. This keeps our repository clean. By executing &#8220;git show&#8221; after committing the .gitignore file you will see that our ignore rules are correctly interpreted.</p>
<p>When you view the Git commit log of the project (&#8220;git log&#8221;) you will see that Git has already automatically used an author name and email address in the commits we did so far. These values are automatically detected by Git that examined your system configuration. You can change your name and email by executing the following commands:<br />
<code><br />
$git config --global user.name Sjoerd Maessen<br />
$git config --global user.email youremail@address.com<br />
</code></p>
<p><strong>Taking advantage of Git</strong><br />
Off course we didn&#8217;t install Git just to add one project and change some basic settings. The power in any version control system is to make checkouts, revert and diff changes. Below you can find some basic commands that you will need to master.<br />
<code><br />
$git checkout thepath<br />
$git diff commitid1 commitid2<br />
$git diff -- filepath<br />
$git revert commitid1<br />
</code><br />
The commands are pretty self explaining like all other commands of Git. If you already worked with other version control systems their is one thing to be aware of, &#8220;git revert&#8221; doesn&#8217;t behave like &#8220;svn revert&#8221; for example. &#8220;Git revert&#8221; will do a new commit to reverse a previous one, if you would like to undo your changes you should use &#8220;git checkout&#8221; instead. The things I have showed above are only small aspects of what Git is capable of. Cloning repo&#8217;s, tagging, branching, patching and resolving conflicts are all aspects that will make your life a lot easier, check them out at the <a href="http://book.git-scm.com/" target="_blank">Git community book</a></p>
<p><strong>One more thing</strong><br />
There are some Git GUI repository browsers available that let you view who, why and when something was committed. One that is easy to setup and PHP only is viewgit, give it a try it will just run from your webserver!<br />
<a href="http://www.sjoerdmaessen.be/wp-content/uploads/Schermafbeelding-2010-06-12-om-20.03.08.png"><img class="alignnone size-medium wp-image-212" title="Viewgit interface" src="http://www.sjoerdmaessen.be/wp-content/uploads/Schermafbeelding-2010-06-12-om-20.03.08-300x124.png" alt="" width="300" height="124" /></a><br />
<a href="http://viewgit.sourceforge.net/" target="_blank">http://viewgit.sourceforge.net</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/06/14/git-tutorial-getting-started-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Input validation with filter functions</title>
		<link>http://www.sjoerdmaessen.be/2010/06/03/the-filter-functions-family-input-validation/</link>
		<comments>http://www.sjoerdmaessen.be/2010/06/03/the-filter-functions-family-input-validation/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 07:27:11 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[sanitizing]]></category>
		<category><![CDATA[validating]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=177</guid>
		<description><![CDATA[Introduction Although PHP has a lot of filter functions available, I found that still to many people are using (often incorrect) regular expressions to validate user input. The filter extension is simple, standard available and will fulfill the common validations. Below some pratical examples and things to consider when working with PHP filter functions. Which [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
Although PHP has a lot of filter functions available, I found that still to many people are using (often incorrect) regular expressions to validate user input. The filter extension is simple, standard available and will fulfill the common validations. Below some pratical examples and things to consider when working with PHP filter functions.<br />
<span id="more-177"></span><br />
<strong>Which are available?</strong><br />
Below a shameless copy paste of the <a href="http://www.php.net/filter" target="_blank">PHP documentation</a>.</p>
<ul>
<li>filter_has_var — Checks if variable of specified type exists</li>
<li>filter_id — Returns the filter ID belonging to a named filter</li>
<li>filter_input_array — Gets external variables and optionally filters them</li>
<li>filter_input — Gets a specific external variable by name and optionally filters it</li>
<li>filter_list — Returns a list of all supported filters</li>
<li>filter_var_array — Gets multiple variables and optionally filters them</li>
<li>filter_var — Filters a variable with a specified filter</li>
</ul>
<p><strong>Pratical use</strong></p>
<p><em>Sanitizing</em><br />
&#8220;Filter input escape output&#8221; every developer knows this but it is a repetitive job but with the filter extension filterering input became a lot easier. When you correctly filter input you drastically lower the change of application vulnerabilities.</p>
<p><em>Sanitizing a single variable</em></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$sText</span> = <span class="st0">&#8216; &lt;script type=&quot;text/javascript&quot;&gt;alert(&quot;comment from scriptkiddie&quot;);&lt;/script&gt;&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$sText</span> = filter_var<span class="br0">&#40;</span><span class="re0">$sText</span>, FILTER_SANITIZE_STRING<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$sText</span>; <span class="co1">// This is a comment from a alert(&amp;#34;scriptkiddie&amp;#34;);</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p><em>Sanitizing multiple variables, same principle as above but with an array, the filter will sanitize all values inside the array</em></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">filter_var_array<span class="br0">&#40;</span><span class="re0">$_POST</span>, FILTER_SANITIZE_STRING<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p><em>Validating an email address</em></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>filter_var<span class="br0">&#40;</span><span class="re0">$sEmail</span>, FILTER_VALIDATE_EMAIL<span class="br0">&#41;</span> === <span class="kw2">false</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="re0">$this</span>-&gt;<span class="me1">addError</span><span class="br0">&#40;</span><span class="st0">&#8216;Invalid email address&#8217;</span>, <span class="re0">$sEmail</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p><em>Validation a complete array</em><br />
Validating all your data at once with a single filter will make your code clear, all in one place and is more easy to maintain an example below.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$aData</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;student&#8217;</span>&nbsp; &nbsp; &nbsp; &nbsp;=&gt; <span class="st0">&#8216;Sjoerd Maessen&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;class&#8217;</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="st0">&#8217;21&#8242;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;grades&#8217;</span> =&gt; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;math&#8217;</span> =&gt; <span class="nu0">9</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;geography&#8217;</span> =&gt; <span class="nu0">66</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;gymnastics&#8217;</span> =&gt; <span class="nu0">7.5</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$aValidation</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;student&#8217;</span>&nbsp; &nbsp; &nbsp; &nbsp;=&gt; FILTER_SANITIZE_STRING,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;class&#8217;</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; =&gt; FILTER_VALIDATE_INT,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;grades&#8217;</span>&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;filter&#8217;</span> =&gt; FILTER_VALIDATE_INT,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;flags&#8217;</span>&nbsp; =&gt; FILTER_FORCE_ARRAY,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;options&#8217;</span>=&gt; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;min_range&#8217;</span>=&gt;<span class="nu0">0</span>, <span class="st0">&#8216;max_range&#8217;</span>=&gt;<span class="nu0">10</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;pre&gt;&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/var_dump"><span class="kw3">var_dump</span></a><span class="br0">&#40;</span>filter_var_array<span class="br0">&#40;</span><span class="re0">$aData</span>, <span class="re0">$aValidation</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/*array(3) {</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; [&quot;student&quot;]=&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; string(14) &quot;Sjoerd Maessen&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; [&quot;class&quot;]=&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; int(21) // Thats strange, my string is converted</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; [&quot;grades&quot;]=&gt;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; array(3) {</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; [&quot;math&quot;]=&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; int(9)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; [&quot;geography&quot;]=&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; bool(false) // 66 is &gt; 10</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; [&quot;gymnastics&quot;]=&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; bool(false) // 7.5 is not an int</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; }</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">}*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p><strong>Note:</strong> okay I did not expect that the string &#8217;21&#8242; would validate true against FILTER_VALIDATE_INT, after some more testing I also noticed that min_range and max_range only work with FILTER_VALIDATE_INT, when using floats or scalars the options are just ignored, so be aware!</p>
<p>The sanitizing examples above can be made easily more restrictive by adding flags like FILTER_FLAG_STRIP_LOW to the sanitize filter, FILTER_FLAG_STRIP_LOW will for example strip all characters that have a numerical value below 32.</p>
<p><strong>Things to consider</strong><br />
Although the filter functions are some time available some of them aren&#8217;t flawless, at some points the documentation is missing or very unclear. Another example is the filter_var validation for IPv6 addresses. (see bug report<a href="http://bugs.php.net/bug.php?id=50117" target="_blank"> #50117</a>). So it is always a good thing to check if the filter is really doing what you expect it does. Write testcases before using. If you use it correctly you can write your validations in the blink of an eye, and this extension will be your new best friend.</p>
<p><strong>Links</strong><br />
<a href="http://nl3.php.net/manual/en/ref.filter.php">Filter functions</a><br />
<a href="http://php.net/manual/fa/filter.filters.flags.php">Filter flags</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/06/03/the-filter-functions-family-input-validation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tips that prevent your mailing being marked as &#8216;spam&#8217;</title>
		<link>http://www.sjoerdmaessen.be/2010/05/03/tips-that-prevent-your-mailing-being-marked-as-spam/</link>
		<comments>http://www.sjoerdmaessen.be/2010/05/03/tips-that-prevent-your-mailing-being-marked-as-spam/#comments</comments>
		<pubDate>Mon, 03 May 2010 06:13:25 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[Mail]]></category>
		<category><![CDATA[newsletter]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=167</guid>
		<description><![CDATA[Introduction The last couple of weeks I was working on writing a mailing/newsletter system myself. One of the first questions that came up was &#8220;how do I prevent that my newsletter will be marked as spam&#8221;. Although this article has nothing to do with PHP I still like to put it in the spotlight. I [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>The last couple of weeks I was working on writing a mailing/newsletter system myself. One of the first questions that came up was &#8220;how do I prevent that my newsletter will be marked as spam&#8221;. Although this article has nothing to do with PHP I still like to put it in the spotlight. I will give some tips on how to avoid your mail being marked as spam, some you will know, others you won&#8217;t.</p>
<p><strong>How is determined if my email is spam?</strong><br />
Mostly this is done by so called spam filters (server side or client side), some well known examples: </p>
<ul>
<li><a target="_blank" href="http://spamassassin.apache.org/">Spam Assasin</a</li>
<li><a target="_blank" href="http://keir.net/k9.html">k9</a></li>
<li><a target="_blank" href="http://www.messagelabs.com/">MessageLabs</a></li>
<li><a href="http://www.cleanport.com/">CleanPort</a></li>
</ul>
<p>Some of them work with the Bayesian filter. This filter is one of the<span id="more-167"></span> most accurate filters available. It will detect 98% of the spam mails by an algorithm. Essentially the filter will check if words occur a lot in spam mails but not in normal mails, if spam words occur a lot in a mail we can assume we are dealing with a spam mail. Before we can use this filter we need to build a database with legitimate words. This database is build by the filter, it monitors all outgoing mails from the user and the incoming mails. By checking which words are used in the outgoing mails from the user it can &#8220;learn&#8221; which words are legitimate. Each word will get a score, the score will represent the probability of the mail being a spam mail (the mail in which the word appears).</p>
<p>An example:<br />
We take the word &#8220;casino&#8221;, let&#8217;s suppose this word occurs in 100 of the 500 spam mails and only in 5 of the 500 legitimate mails. The spam score for this word will be:</p>
<p>(100/500) / (5/500 + 100/500) = 0,95</p>
<p>Off course spam filters use a lot of other techniques too.</p>
<p><strong>Tips to lower your spamscore</strong><br />
I hope you now have a more clear understanding of how the most spam filters work. So lets start with some tips. </p>
<ul>
<li>don&#8217;t use words and phrases that are often used in spam mails, for a small list see the <a target="_blank" "href="http://office.microsoft.com/en-us/help/HA010450051033.aspx">Microsoft Junk E-Mail Filter Readme</a>, also the use of complete phrases in capitals is killing.</li>
<li>use a dedicated mailserver, why? Most filters will recognize the IP from which a mail is coming, if the mailserver IP is recognized as a server from which the filter is getting legitimate mails more often, it will work in your advantage</li>
<li>Don&#8217;t send any attachments with a mailing, virus scanners aren&#8217;t too happy about them, neither are spam filters</li>
<li>Send good content. Try to make the content of each newsletter as different as possible, filters will recognize texts that have occurred before. Also pay attention not to send just one big image and just a few lines of text, you will get a penalty for that one too. Find a balance between the amount of images, the size of them, and the amount of text.</li>
<li>Use a real mail address from which the newsletter is coming, filters will often check the domain (using an address with a domain like hotmail, gmail, yahoo,&#8230; doesn&#8217;t count).</li>
<li>Don&#8217;t use url shorteners, url shorteners like bit.ly or TinyUrl are often used by spammers</li>
</ul>
<p>A last one, but nevertheless an important one &#8220;don&#8217;t prevent your mail being marked as spam&#8221;. Okay that sounds silly right? What I mean is that if you write a whole paragraph in your mailing about how someone can unsubscribe this will be seen as suspicious also avoid text like &#8220;this is not spam&#8221;.</p>
<p>More tests that will possibly increase your spam score can be found on the website of <a target="_blank" href="http://spamassassin.apache.org/tests_3_0_x.html">SpamAssassin</a>. Some tests that caught my eye:</p>
<ul>
<li>use of the tbody html tag</li>
<li>message body has many words used only once (this one increases your spam score a lot)</li>
<li>Invalid date in header (wrong EST timezone)</li>
</ul>
<p>Keep the above in mind when writing your next mailing <img src='http://www.sjoerdmaessen.be/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  good luck!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/05/03/tips-that-prevent-your-mailing-being-marked-as-spam/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP alternative, lazy syntax</title>
		<link>http://www.sjoerdmaessen.be/2010/04/12/php-alternative-lazy-syntax/</link>
		<comments>http://www.sjoerdmaessen.be/2010/04/12/php-alternative-lazy-syntax/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 18:22:50 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[syntax]]></category>
		<category><![CDATA[alternative]]></category>
		<category><![CDATA[format]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=136</guid>
		<description><![CDATA[Alternative, lazy what? Consider the next example: &#160; &#60;?php foreach&#40;$aNewsItems as $oItem&#41; &#123; &#160; &#160; &#160;echo &#8216;&#60;li&#62;&#8217;; &#160; &#160; &#160;echo &#8216;&#60;a href=&#34;/news/&#8217;.$oItem-&#62;id.&#8216;-&#8217;.$oItem-&#62;rewrite.&#8216;.html&#34;&#62;&#8217;.$oItem-&#62;title.&#8216;&#60;/a&#62;&#8217;; &#160; &#160; &#160;echo &#8216;&#60;/li&#62;&#8217;; &#125; ?&#62; &#160; We could write the above like this: &#160; &#60;?php foreach&#40;$aNewsItems as $oItem&#41;: ?&#62; &#160; &#160; &#160;&#60;li&#62; &#160; &#160; &#160; &#160; &#160; &#60;a href=&#34;/news/&#60;?=$oItem-&#62;id?&#62;-&#60;?=$oItem-&#62;rewrite?&#62;.html&#34;&#62;&#60;?=$oItem-&#62;title?&#62;&#60;/a&#62; &#160; &#160; &#160;&#60;/li&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Alternative, lazy what?</strong></p>
<p>Consider the next example:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span> <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$aNewsItems</span> <span class="kw1">as</span> <span class="re0">$oItem</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;li&gt;&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;a href=&quot;/news/&#8217;</span>.<span class="re0">$oItem</span>-&gt;<span class="me1">id</span>.<span class="st0">&#8216;-&#8217;</span>.<span class="re0">$oItem</span>-&gt;<span class="me1">rewrite</span>.<span class="st0">&#8216;.html&quot;&gt;&#8217;</span>.<span class="re0">$oItem</span>-&gt;<span class="me1">title</span>.<span class="st0">&#8216;&lt;/a&gt;&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp;<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;/li&gt;&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>We could write the above like this: <span id="more-136"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span> <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$aNewsItems</span> <span class="kw1">as</span> <span class="re0">$oItem</span><span class="br0">&#41;</span>: <span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;&lt;li&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=<span class="st0">&quot;/news/&lt;?=$oItem-&gt;id?&gt;-&lt;?=$oItem-&gt;rewrite?&gt;.html&quot;</span>&gt;&lt;?=<span class="re0">$oItem</span>-&gt;<span class="me1">title</span>?&gt;&lt;/a&gt;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp;&lt;/li&gt;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span> <span class="kw1">endforeach</span>; <span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Personally I think the second example is much easier to understand and a lot clearer for someone who isn&#8217;t familiar with PHP then the second one. (unfortunately my code highlight plugin thinks different though <img src='http://www.sjoerdmaessen.be/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) No braces in the code will also prevent some people to get the idea it&#8217;s to difficult to use PHP inside HTML and that integrating PHP into HTML is a task for PHP developers only. Also notice the advantage when indenting the HTML code.<br />
Futher it helps me to distinguish in my own projects template files and controllers, models,&#8230; because of the different syntax. So when I have a a file with mixed PHP and HTML this is the preferred way for me. </p>
<p><strong>Great! Let&#8217;s start using it!</strong><br />
Good idea but bear in mind that their are a few drawbacks:</p>
<ul>
<li>Not all servers allow the shorttags (check the short_open_tag entry in your php.ini file)</li>
<li>Not using ; in the above example is a bad practice and should be avoided</li>
<li>The most important one, their are other template engines on the market like <a target="_blank" href="http://www.smarty.net/">Smarty</a>, <a href="http://dwoo.org/" target="_blank">Dwoo</a>, <a href="http://phpsavant.com/" target="_blank">Savant</a>, <a href="http://www.templateblocks.com/" target="_blank">Template Blocks</a> and a lot more that do the same thing but then easier or better (although you have minimal overhead)</li>
</ul>
<p>Futher I should note their are some heavy discussions (still?) going on in the PHP community whether the short tags are genius or just plain evil. One thing is pretty sure now the short tags will still be available in PHP version 6.</p>
<p>For the complete list of the alternative syntax visit <a target="_blank" href="http://www.php.net/manual/en/control-structures.alternative-syntax.php">php.net</a></p>
<p>Please fill in the <a target="_blank" href="http://twtpoll.com/ue1z9m">poll</a> and leave a comment.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/04/12/php-alternative-lazy-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing the Joel test &#8211; step 1 setting up a versioning system for Windows</title>
		<link>http://www.sjoerdmaessen.be/2010/03/20/passing-the-joel-test-step-1-setting-up-a-versioning-system-for-windows/</link>
		<comments>http://www.sjoerdmaessen.be/2010/03/20/passing-the-joel-test-step-1-setting-up-a-versioning-system-for-windows/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 09:00:54 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[joeltest]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[versioning]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=114</guid>
		<description><![CDATA[Until the last PHP conference I attended (the PHP benelux conference 2010) I used an normal Windows XP installation with a Zend Server CE installation on it at home, and yeah it worked. At the office we already used versioning, bug tracking and some other Joel points. I could see the advantages clearly, even if [...]]]></description>
			<content:encoded><![CDATA[<p>Until the last PHP conference I attended (the PHP benelux conference 2010) I used an normal Windows XP installation with a Zend Server CE installation on it at home, and yeah it worked. At the office we already used versioning, bug tracking and some other Joel points. I could see the advantages clearly, even if I was developing on my own at home but I just couldn&#8217;t find time and motivation to start converting my home server to something more serious. That is until I attended a track on the Joel test of <a href="http://www.lornajane.net/">lornajane</a>. (Slides are available <a href="http://www.slideshare.net/lornajane/passing-the-joel-test-in-the-php-world-phpbnl10">here</a>). I thought it would be a nice idea to keep my Windows installation on the server during this adventure to pass the Joel test.<span id="more-114"></span></p>
<p><strong>The first step:</strong> setting up a versioning system.<br />
I chose <a href="http://mercurial.selenic.com">Mercurial</a> not because I think it&#8217;s the best, not because it&#8217;s the easiest one but just because I didn&#8217;t know anything about it yet. (and maybe a little bit because I already saw it had a prepackaged version for Windows)</p>
<p>Installing Mercurial was really easy it only take like 3 minutes before everything was running and I had my first repository created. I could explain what I did but actually I just followed this<a href="http://mercurial.selenic.com/wiki/WindowsInstall#Compile_and_Install"> manual</a> can&#8217;t get much easier then that. Because I use Netbeans as my main IDE I could start working right away, Netbeans as build in Mercurial support.<br />
<a href="http://www.sjoerdmaessen.be/wp-content/uploads/netbeans-mercurial.jpg"><img src="http://www.sjoerdmaessen.be/wp-content/uploads/netbeans-mercurial-300x273.jpg" alt="" title="netbeans-mercurial" width="300" height="273" class="alignnone size-medium wp-image-139" /></a></p>
<p>One thing I really liked about my Windows pc at work is that has Tortoise SVN installed for repobrowsing and a lot more.  Now Tortoise SVN is not an option when using Mercurial, but hey there is a good alternative called <a href="http://tortoisehg.bitbucket.org/">Tortoise HG</a>.<br />
<a href="http://www.sjoerdmaessen.be/wp-content/uploads/tortoise-hg.jpg"><img src="http://www.sjoerdmaessen.be/wp-content/uploads/tortoise-hg-300x170.jpg" alt="" title="tortoise-hg" width="300" height="170" class="alignnone size-medium wp-image-142" /></a></p>
<p>Because I mainly use OSX at home I also installed Mercurial on my Mac, again, it worked immediately.<br />
<a href="http://www.sjoerdmaessen.be/wp-content/uploads/terminal-mercurial.jpg"><img src="http://www.sjoerdmaessen.be/wp-content/uploads/terminal-mercurial-300x248.jpg" alt="" title="terminal-mercurial" width="300" height="248" class="alignnone size-medium wp-image-143" /></a></p>
<p>I must say setting up a versioning system can&#8217;t get much easier then this, I expected a lot hassle but it all went very smooth, thumbs up for Mercurial!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/03/20/passing-the-joel-test-step-1-setting-up-a-versioning-system-for-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction into SOAP, setting up a simple webservice with PHP SOAP</title>
		<link>http://www.sjoerdmaessen.be/2010/02/11/introduction-into-soap-setting-up-a-simple-webservice-with-php-soap/</link>
		<comments>http://www.sjoerdmaessen.be/2010/02/11/introduction-into-soap-setting-up-a-simple-webservice-with-php-soap/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 12:26:39 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[SOAP]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=115</guid>
		<description><![CDATA[I was asked to create a simple webservice that would allow us to transfer a intranet post to an external CMS. In this post I will explain the steps you must take to set-up a simple webservice with the PHP SOAP extension. The first step, create a simple class that we will use to request [...]]]></description>
			<content:encoded><![CDATA[<p>I was asked to create a simple webservice that would allow us to transfer a intranet post to an external CMS. In this post I will explain the steps you must take to set-up a simple webservice with the <a href="http://nl.php.net/manual/en/book.soap.php">PHP SOAP extension</a>.</p>
<p><strong>The first step, create a simple class that we will use to request data from</strong><br />
We will create a class with one method that returns a string with the parameter we called it. The method will accept one parameter and will check if the value is correct.<br />
<span id="more-115"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Blog service class</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> BlogService</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Return a blogpost</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param string $sID</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return string test data</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">function</span> getItem<span class="br0">&#40;</span><span class="re0">$sID</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$iID</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; = <span class="br0">&#40;</span>int<span class="br0">&#41;</span><span class="re0">$sID</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$aValidIds</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span>, <span class="nu0">5</span><span class="br0">&#41;</span>; <span class="co1">// Notice the missing id number 4</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// Check if we requested a valid blogpost id</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span>!<a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span><span class="re0">$iID</span>, <span class="re0">$aValidIds</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">return</span> <span class="kw2">new</span> SoapFault<span class="br0">&#40;</span><span class="st0">&#8216;Server&#8217;</span>, <span class="st0">&#8216;Blogpost with id &#8216;</span>.<span class="re0">$iID</span>.<span class="st0">&#8216; not found!&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">return</span> <span class="st0">&#8216;Blogpost with id &#8216;</span>.<span class="re0">$iID</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Nothing special here, notice that we don&#8217;t throw a normal exception but <strong>return </strong> the SoapFault instead so we can handle the error clientside.</p>
<p><strong>The second step, create a WSDL document</strong></p>
<p>The WSDL document is a simple XML document that describes:<br />
- the service itself<br />
- the operations of the service<br />
- the data types used in the service</p>
<p>The WSDL will describe our method getItem from our Blog service class so we can call it later on.</p>
<p>So how does this WSDL thing look like?</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Init the server</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$oServer</span> = <span class="kw2">new</span> SoapServer<span class="br0">&#40;</span><span class="st0">&#8216;blog.wsdl&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Register the blog service class and all the methods</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$oServer</span>-&gt;<span class="me1">setClass</span><span class="br0">&#40;</span><span class="st0">&#8216;BlogService&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Rock &#8216;n roll</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$oServer</span>-&gt;<span class="me1">handle</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p><strong>The fourth and final step, test our webservice</strong></p>
<p>Its a good idea to test the webservice with a program like <a href="http://www.soapui.org/">soapUI</a>, it often can provide some additional information when troubleshooting. (They have a free version available on their website).</p>
<p>To test our webservice in PHP we can use the following code:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/ini_set"><span class="kw3">ini_set</span></a><span class="br0">&#40;</span><span class="st0">&quot;soap.wsdl_cache_enabled&quot;</span>, <span class="st0">&quot;0&quot;</span><span class="br0">&#41;</span>; <span class="co1">// Disable the wsdl cache</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$oClient</span> = <span class="kw2">new</span> SoapClient<span class="br0">&#40;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Url to our wsdl, http://{siteUrl}/webservice/index.php?wsdl is also possible</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;{siteUrl}/webservice/blog.wsdl&#8217;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;trace&#8217;</span> &nbsp;=&gt; <span class="kw2">true</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;exceptions&#8217;</span>=&gt; <span class="kw2">true</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">try <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$aResult</span> = <span class="re0">$oClient</span>-&gt;<span class="me1">getItem</span><span class="br0">&#40;</span><span class="nu0">4</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/var_dump"><span class="kw3">var_dump</span></a><span class="br0">&#40;</span><span class="re0">$aResult</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span> catch <span class="br0">&#40;</span>SoapFault <span class="re0">$e</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/exit"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="re0">$e</span>-&gt;<span class="me1">faultstring</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>You should see a SOAP fault, because the id number 4 we gave to the getItem function didn&#8217;t exist in our Blog service class. Change the value to 1,2,3 or 5 and you should get a nice response back.<br />
Another pretty neat function is $oClient->__getFunctions(); it will return all the function that are available in the webservice.</p>
<p>This was just a short introduction to SOAP, a lot more is possible with SOAP.<br />
Special thanks to <a href="http://twitter.com/dzuelke">David Zuelke</a> for the nice SOAP introduction at the <a href="http://conference.phpbenelux.eu/">PHPbenelux conference 2010</a>.</p>
<p>Example files:<br />
<a href="http://www.sjoerdmaessen.be/media/webservice.rar">Webservice.rar</a></p>
<p>Just deploy the example files on your webserver, change the {siteUrl} values in the files with your domain and call the client.php</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/02/11/introduction-into-soap-setting-up-a-simple-webservice-with-php-soap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limit the number of newlines in a string</title>
		<link>http://www.sjoerdmaessen.be/2010/01/28/limit-the-number-of-newlines-in-a-string/</link>
		<comments>http://www.sjoerdmaessen.be/2010/01/28/limit-the-number-of-newlines-in-a-string/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 21:44:14 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[Regexp]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[user input]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=106</guid>
		<description><![CDATA[A very short blog post this time. I often use the following short function to limit the number of breaks/newlines in comments that people can submit on a news article or other user input. You can easily limit the number of characters in a comment by using the PHP strlen function, but the comment can [...]]]></description>
			<content:encoded><![CDATA[<p>A very short blog post this time. I often use the following short function to limit the number of breaks/newlines in comments that people can submit on a news article or other user input. You can easily limit the number of characters in a comment by using the PHP strlen function, but the comment can still use a lot of vertical space on your website if the user uses 5 breaks in his comment. See the function below to prevent this type of comments:<br />
<span id="more-106"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* limitBreaks, prevents texts with a lot of enters/breaks after each other</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp;* @param string $sText</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @param int $iAmount default 2, numbers of newlines that may occur after eachother</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @return string, cleaned up string with limited number of newlines</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> limitBreaks<span class="br0">&#40;</span><span class="re0">$sText</span>, <span class="re0">$iAmount</span>=<span class="nu0">2</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <a href="http://www.php.net/preg_replace"><span class="kw3">preg_replace</span></a><span class="br0">&#40;</span><span class="st0">&quot;/[<span class="es0">\r</span><span class="es0">\n</span>]{&quot;</span>.<span class="br0">&#40;</span><span class="re0">$iAmount</span><span class="nu0">+1</span><span class="br0">&#41;</span>.<span class="st0">&quot;,}<span class="es0">\t</span>*[<span class="es0">\r</span><span class="es0">\n</span>]*/&quot;</span>, <a href="http://www.php.net/str_repeat"><span class="kw3">str_repeat</span></a><span class="br0">&#40;</span>PHP_EOL, <span class="re0">$iAmount</span><span class="br0">&#41;</span>, <span class="re0">$sText</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>As you can see a simple but effective function.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/01/28/limit-the-number-of-newlines-in-a-string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the Google currency converter</title>
		<link>http://www.sjoerdmaessen.be/2010/01/11/using-the-google-currency-converter/</link>
		<comments>http://www.sjoerdmaessen.be/2010/01/11/using-the-google-currency-converter/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 19:56:45 +0000</pubDate>
		<dc:creator>Sjoerd Maessen</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[currency]]></category>

		<guid isPermaLink="false">http://www.sjoerdmaessen.be/?p=100</guid>
		<description><![CDATA[For a project I&#8217;m working, I needed to get shipping rates from the UPS API (a blog post about this will follow soon). The problem I ran into was that the UPS API returns the shipping rates with the currency of the country where the rates for are asked, so you can&#8217;t force it to [...]]]></description>
			<content:encoded><![CDATA[<p>For a project I&#8217;m working, I needed to get shipping rates from the UPS API (a blog post about this will follow soon).</p>
<p>The problem I ran into was that the UPS API returns the shipping rates with the currency of the country where the rates for are asked, so you can&#8217;t force it to always return the rates in EUR.</p>
<p>One solution to convert the prices is to make a very big array with all currency rates in it. I then would maintain the array every day at 9&#8242;o clock to check if the rates weren&#8217;t changed. Right, that&#8217;s not an option.<br />
<span id="more-100"></span><br />
Like you might know you can easily convert currencies by using the Google search engine. For example searching on <a target="_blank" href="http://www.google.com/search?q=1+Euro+to+dollar&#038;ie=UTF-8&#038;oe=UTF-8">&#8220;1 Euro to dollar&#8221;</a> will retrieve the Euro in dollar.</p>
<p>Below the class I wrote to convert currencies using the Google currency converter.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Convert from one currency to another</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @author Sjoerd Maessen</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Currency_Convertor</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Url of the google currency convertor</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @var string</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$sConvertorUrl</span> = <span class="st0">&#8216;http://www.google.com/ig/calculator?hl=en&amp;q=%s%s=?%s&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Price to convert</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @var float</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$fPrice</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* From currency code</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @var string</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$sFrom</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* To currency code</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @var string</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$sTo</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Build up our query url and catch errors</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return boolean $bResult</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> <a href="http://www.php.net/exec"><span class="kw3">exec</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$bResult</span>&nbsp; &nbsp; &nbsp; &nbsp; = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sUrl</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; = <a href="http://www.php.net/sprintf"><span class="kw3">sprintf</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">sConvertorUrl</span>, <span class="re0">$this</span>-&gt;<span class="me1">fPrice</span>, <span class="re0">$this</span>-&gt;<span class="me1">sFrom</span>, <span class="re0">$this</span>-&gt;<span class="me1">sTo</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sResponse</span> = <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="re0">$sUrl</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>!<span class="re0">$sResponse</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw <span class="kw2">new</span> Exception<span class="br0">&#40;</span><span class="st0">&#8216;Google currency convertor is not available at the moment&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$oResult</span> = json_decode<span class="br0">&#40;</span><span class="re0">$sResponse</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$oResult</span>-&gt;<span class="me1">error</span> != <span class="st0">&#8221;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw <span class="kw2">new</span> Exception<span class="br0">&#40;</span><span class="st0">&#8216;The following error occurred: &#8216;</span>.<span class="re0">$oResult</span>-&gt;<span class="me1">error</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Isolate the price</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>float<span class="br0">&#41;</span><span class="re0">$oResult</span>-&gt;<span class="me1">rhs</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Get, retrieve the foreign currency</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param float $fPrice</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param string $sFrom, currency code (EUR, USD,&#8230;)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param string $sTo, currency code (EUR, USD,&#8230;)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> get<span class="br0">&#40;</span><span class="re0">$fPrice</span>, <span class="re0">$sFrom</span>, <span class="re0">$sTo</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>!<a href="http://www.php.net/is_float"><span class="kw3">is_float</span></a><span class="br0">&#40;</span><span class="re0">$fPrice</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw <span class="kw2">new</span> Exception<span class="br0">&#40;</span><span class="st0">&#8216;The price to convert should be a float, &quot;&#8217;</span>.<a href="http://www.php.net/gettype"><span class="kw3">gettype</span></a><span class="br0">&#40;</span><span class="re0">$fPrice</span><span class="br0">&#41;</span>. <span class="st0">&#8216;&quot; given while calling: &#8216;</span>.<span class="kw2">__FUNCTION__</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">fPrice</span>&nbsp; &nbsp;= <span class="re0">$fPrice</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">sFrom</span>&nbsp; &nbsp; = <a href="http://www.php.net/strtoupper"><span class="kw3">strtoupper</span></a><span class="br0">&#40;</span><span class="re0">$sFrom</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">sTo</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = <a href="http://www.php.net/strtoupper"><span class="kw3">strtoupper</span></a><span class="br0">&#40;</span><span class="re0">$sTo</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$this</span>-&gt;<span class="me1">exec</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>Pretty straightforward as you see.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sjoerdmaessen.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sjoerdmaessen.be/2010/01/11/using-the-google-currency-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
