<?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>Patrick&#039;s playground &#187; PHP</title>
	<atom:link href="http://www.vankouteren.eu/blog/category/scripting/scripting-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vankouteren.eu/blog</link>
	<description>Random thoughts, problems and solutions</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:53:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP SPL data structure: SplFixedArray</title>
		<link>http://www.vankouteren.eu/blog/2011/09/php-spl-data-structure-splfixedarray/</link>
		<comments>http://www.vankouteren.eu/blog/2011/09/php-spl-data-structure-splfixedarray/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 14:51:31 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[memory usage]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[SplFixedArray]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=267</guid>
		<description><![CDATA[PHP 5.3 introduced some new data structures. The talk of Jurriën Stutterheim on PFCongres 2011 on SPL structures and their performance triggered me to have a closer look at the performance of these structures. I was kind of fooled by two comments on the PHP.net page, so it was time to find out myself. For [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
<p>PHP 5.3 introduced some new data structures. The talk of Jurriën Stutterheim on<a title="PFCongres" href="http://www.pfcongres.nl/"> PFCongres 2011</a> on SPL structures and their performance triggered me to have a closer look at the performance of these structures. I was kind of fooled by two comments on the <a title="SplFixedArray PHP.net page" href="http://www.php.net/manual/en/class.splfixedarray.php">PHP.net page</a>, so it was time to find out myself.</p>
<p><span id="more-267"></span>For people familiar with Java the SplFixedArray is not a strange structure as they are common structures in this language. PHP only used arrays in the past.</p>
<p>The common array structure may contain all kind of keys (one can use strings, integers and even combine them) and under the hood PHP uses a hashing algorithm to create a unique array index for these keys. So actually under the hood these arrays are comparable to Java HashMaps. Like a database can create indexes on keys, PHP creates an index on the hashed indexes to speed up item retrieval from the array. However: hashing does not guarantee a unique output for every unique input. It may well be that two completely different keys result in a same hashed value. A hashing algorithm can sort this out in its own way (there are various way to do this, but I think this is out of the scope of this post right now), so there's another level of complexity here.</p>
<p>The new SplFixedArray has a pre-defined size and can only contain integer keys. As the size is limited this saves memory and the indexing is done more efficient. It does away with all hashing related issues which saves time. Now the question is: how much time does it save me?</p>
<p><strong>Hey: we're running PHP, not Java.. I didn't have to bother with memory usage, why would I do that now all of a sudden?</strong></p>
<p>You don't have to if you don't like to, but there may be a lot to gain for you. Especially when you are using a lot of arrays of which you know the size beforehand as well as the positions of items. In an environment which often is under heavy load the benefits of SplFixedArray may come in handy for you. (And updating software is cheaper than updating hardware..)</p>
<p><strong>Numbers</strong></p>
<p>As I said I was fooled at first by two comments on the <a title="PHP.net SplFixedArray" href="http://www.php.net/manual/en/class.splfixedarray.php">PHP.net manual</a>: <a title="SplFixedArray test 1" href="http://www.php.net/manual/en/class.splfixedarray.php#92214">this one</a> and <a title="SplFixedArray test 2" href="http://www.php.net/manual/en/class.splfixedarray.php#94179">this one</a>.</p>
<p>The first one tests the speed of insertions in the regular array and the speed of insertions in the SplFixedArray and returns all positives for the SplFixedArray.</p>
<p>The latter one claims to be more realistic, but results in a fatal error directly because the author is trying to insert items on positions outside the range of the SplFixedArray (index out of bounds exception, also common in Java). If this is a realistic example I would reconsider using PHP <img src='http://www.vankouteren.eu/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I've compiled a simple script to test the speeds and memory sizes of array vs SplFixedArray. To (kind of) prevent small background processes influencing the results these tests are done multiple times and averaged. The results are shown below. Please note that these results may vary every time you execute the script. However: the larger the size of the array, the less variance occurs and the more reliable the numbers are.</p>
<p><em>script:</em></p>
<p><pre class="brush: php">&lt;?php

$maxSize = (int) $_GET['size'];
$times = (int) $_GET['times'];

set_time_limit(0);

echo &quot;&lt;h2&gt;Number of repeated tests: &quot; . $times . &quot;&lt;/h2&gt;&quot;;
echo &quot;&lt;table border='1'&gt;&quot;;
echo &quot;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Items&lt;/th&gt;&lt;th&gt;Time Array&lt;/th&gt;&lt;th&gt;Memory Array&lt;/th&gt;&lt;th&gt;SplFixedArray&lt;/th&gt;&lt;th&gt;Memory SplFixedArray&lt;/th&gt;&lt;th&gt;Array/SplFixedArray ratio&lt;/th&gt;&lt;th&gt;Speed increase by SplFixedArray&lt;/th&gt;&lt;th&gt;Memory reduction by SplFixedArray&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&quot;;
echo &quot;&lt;tbody&gt;&quot;;

for($size = 1000; $size &lt; $maxSize; $size *= 2) {
	
	echo &quot;&lt;tr&gt;&lt;td align='right'&gt;&quot; . $size . &quot;&lt;/td&gt;&quot;;
	
	$arrTotal = 0;
	$arrMemUsage = 0;
	for($time = 0; $time &lt; $times; $time++){
		$mStart = memory_get_usage();
		$container1 = array();
		for($s = microtime(true), $i = 0; $i &lt; $size; $i++) {
			$container1[$i] = 1;
		}
		
		$arrMemUsage += (memory_get_usage() - $mStart);
		$arrTime = (microtime(true) - $s);
		$arrTotal += $arrTime;
	}
	
	$avgArrMem = ($arrMemUsage / $times);
	$avgArr = ($arrTotal / $times);
	echo &quot;&lt;td align='right'&gt;&quot; . $avgArr  . &quot;&lt;/td&gt;&quot;;
	echo &quot;&lt;td align='right'&gt;&quot; . $avgArrMem . &quot;&lt;/td&gt;&quot;;
	// Cleanup to REDUCE the influence of memory blocks on the result
	unset($arrTotal);
	unset($arrMemUsage);
	unset($container1);
	
	$splFixedArrTotal = 0;
	$splFixedArrMemUsage = 0;
	for($time = 0; $time &lt; $times; $time++){
		$mStart = memory_get_usage();
		$container2 = new SplFixedArray($size);
		for($s = microtime(true), $i = 0; $i &lt; $size; $i++) {
			$container2[$i] = 1;
		}
		
		$splFixedArrMemUsage += (memory_get_usage() - $mStart);
		$splFixedArrTime = (microtime(true) - $s);
		$splFixedArrTotal += $splFixedArrTime;
	}
	
	$avgSplFixedArrMem = ($splFixedArrMemUsage / $times);
	$avgSplFixedArr = ($splFixedArrTotal / $times);
	echo &quot;&lt;td align='right'&gt;&quot; . $avgSplFixedArr . &quot;&lt;/td&gt;&quot;;
	echo &quot;&lt;td align='right'&gt;&quot; . $avgSplFixedArrMem . &quot;&lt;/td&gt;&quot;;
	// Cleanup to REDUCE the influence of memory blocks on the result
	unset($splFixedArrTotal);
	unset($splFixedArrMemUsage);
	unset($container2);
	
	// Calculate ratio
	echo &quot;&lt;td align='right'&gt;&quot; . ($avgArr / $avgSplFixedArr) . &quot;&lt;/td&gt;&quot;;
	// Calculate speed increase percentage
	echo &quot;&lt;td align='right'&gt;&quot; . number_format(((($avgSplFixedArr - $avgArr) / $avgArr) * -100), 4) . &quot; %&lt;/td&gt;&quot;;
	// Calculated memory reduction percentage
	if ($avgArrMem == 0){
		echo &quot;&lt;td align='right'&gt;NaN&lt;/td&gt;&lt;/tr&gt;&quot;;
	}
	else {
		echo &quot;&lt;td align='right'&gt;&quot; . number_format(((($avgSplFixedArrMem - $avgArrMem) / $avgArrMem) * -100), 4) . &quot; %&lt;/td&gt;&lt;/tr&gt;&quot;;
	}
	
	// Cleanup to REDUCE the influence of memory blocks on the result
	unset($avgArr);
	unset($avgSplFixedArr);

}

echo &quot;&lt;/tbody&gt;&lt;/table&gt;&quot;;

?&gt;</pre></p>
<p><em>results:</em></p>
<p><a href="http://www.vankouteren.eu/blog/wp-content/uploads/2011/09/arrayvssplfixedarrayresult.jpg">Results (regular table didn't fit the page)</a></p>
<p><strong>So what does it say?</strong></p>
<p><strong></strong>Well regarding the memory the usage has been decreased by around 58% in this case. This, of course, is due to the fact that the SplFixedArray has a limited size and therefor a (pre-defined) limited space in the memory reserved. There is some gain in speed as well.</p>
<p><strong>So is it better to use?</strong></p>
<p>That really depends. The SplFixedArray has some advantages, but also some drawbacks compared to the common array. It should be used where it fits: if you need an array of a size which can be pre-defined and where you need integer keys. It's also a good (at least, I think.. but I started with Java..) habit to use the appropriate data structures.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2011/09/php-spl-data-structure-splfixedarray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Propel and the zero date issue</title>
		<link>http://www.vankouteren.eu/blog/2011/06/propel-and-the-zero-date-issue/</link>
		<comments>http://www.vankouteren.eu/blog/2011/06/propel-and-the-zero-date-issue/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 11:58:47 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[0000-00-00]]></category>
		<category><![CDATA[Propel 1.5.4]]></category>
		<category><![CDATA[Propel 1.6.0]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=255</guid>
		<description><![CDATA[Today I was unpleasantly surprised by a change in behavior when upgrading Propel from version 1.5.4 to 1.6. I frequently use zero dates in MySQL ('0000-00-00') and these dates are affected by the upgrade. As it was deployment time I had to find a solution quickly. This post outlines what the problem is and what [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
<p>Today I was unpleasantly surprised by a change in behavior when upgrading Propel from version 1.5.4 to 1.6. I frequently use zero dates in MySQL ('0000-00-00') and these dates are affected by the upgrade. As it was deployment time I had to find a solution quickly. This post outlines what the problem is and what I did to solve it.<span id="more-255"></span><br />
So what's all the fuzz about? It's about a query like this:<br />
<pre class="brush: php">$contractObjectCollection = ContractQuery::create()
            -&gt;filterByOrderId($this-&gt;getID())
            -&gt;condition('contractToAfterNow', 'Contract.ContractTo &gt; ?', date('Y-m-d'))
            -&gt;condition('contractToIsNul', 'Contract.ContractTo = ?', '0000-00-00')
            -&gt;combine(array('contractToAfterNow', 'contractToIsNul'), 'or', 'contractToCondition')
            -&gt;condition('contractFromIsFilledIn', 'Contract.ContractFrom &lt;= ?', date('Y-m-d'))
            -&gt;combine(array('contractToCondition', 'contractFromIsFilledIn'))
            -&gt;orderByContractFrom('asc')
            -&gt;orderByContractId('asc')
            -&gt;find();</pre></p>
<p>This query gathers contracts which are active (e.g. valid, started and not ended) at this moment.<br />
In Propel 1.5.4 this code translates to the following query:<br />
<pre class="brush: sql">SELECT contract.* FROM `contract` WHERE contract.ORDER_ID='1' AND ((contract.CONTRACT_TO &gt; '2011-06-07' OR contract.CONTRACT_TO = '0000-00-00') AND contract.CONTRACT_FROM &lt;= '2011-06-07') ORDER BY contract.CONTRACT_FROM ASC,contract.CONTRACT_ID ASC</pre></p>
<p>However, in Propel 1.6.0 the code translates to:<br />
<pre class="brush: sql">SELECT contract.* FROM `contract` WHERE contract.ORDER_ID='1' AND ((contract.CONTRACT_TO &gt; '2011-06-07' OR contract.CONTRACT_TO = '-0001-11-30') AND contract.CONTRACT_FROM &lt;= '2011-06-07') ORDER BY contract.CONTRACT_FROM ASC,contract.CONTRACT_ID ASC</pre></p>
<p>Instead of putting 0000-00-00 in the query, the date is translated to -0001-30-11. (Should I read this as 30th of November 1969?)<br />
As my code relies heavily on the outcome of the query, I had to find a quick solution. After some informing on IRC I learned that there seems to be an issue concerning these zero dates (Propel prefers using NULL instead of 0000-00-00, but my application is a legacy application).<br />
The actual solution comes down to writing the query by hand, using the (Debug)PDO instance for querying and using the PropelObjectFormatter to hydrate the results back into the objects you want to be working with.</p>
<p><pre class="brush: php">$query = &quot;SELECT contract.*
        FROM `contract` WHERE contract.ORDER_ID=1&quot;
             AND ((contract.CONTRACT_TO &gt; '&quot; . date('Y-m-d') .
            &quot;' OR contract.CONTRACT_TO = '0000-00-00') AND contract.CONTRACT_FROM &lt;= '&quot; . date('Y-m-d') . &quot;')
            ORDER BY contract.CONTRACT_FROM ASC,contract.CONTRACT_ID ASC&quot;;

        $con = Propel::getConnection();
        $stmt = $con-&gt;prepare($query);
        $stmt-&gt;execute();

        $formatter = new PropelObjectFormatter();
        $formatter-&gt;setClass('Contract');
        $contractObjectCollection = $formatter-&gt;format($stmt);</pre></p>
<p>And that's it. It cost me a little time to figure this out, but my deployment was saved.</p>
<p><strong>Slight note</strong><br />
Please note that Propel normally puts all fields separately in the SELECT statement, but that I've shortened it by putting down the * sign</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2011/06/propel-and-the-zero-date-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting a CLI script from PHP</title>
		<link>http://www.vankouteren.eu/blog/2010/06/starting-a-cli-script-from-php/</link>
		<comments>http://www.vankouteren.eu/blog/2010/06/starting-a-cli-script-from-php/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 10:05:45 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[background process]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[ignore_user_abort]]></category>
		<category><![CDATA[passthru]]></category>
		<category><![CDATA[pcntl]]></category>
		<category><![CDATA[shell_exec]]></category>
		<category><![CDATA[system]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=205</guid>
		<description><![CDATA[For quite some time I've searched for a way to start a command line script from within a page in PHP without using the crontab. Basically I just wanted to start a script which does some processing in the background. The solution is pretty simple, but it took me some time to find it.We all [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
<p>For quite some time I've searched for a way to start a command line script from within a page in PHP without using the crontab. Basically I just wanted to start a script which does some processing in the background. The solution is pretty simple, but it took me some time to find it.<span id="more-205"></span>We all know the crontab: it can execute a script at a particular moment for you, based on what you define to be the moment. But what if you want to execute a background at the moment you would like to?</p>
<p>PHP defines four methods which can execute commands: <a title="exec" href="http://www.php.net/manual/en/function.exec.php" target="_blank">exec</a>, <a title="passthru" href="http://www.php.net/manual/en/function.passthru.php" target="_blank">passthru</a>, <a title="shell_exec" href="http://www.php.net/manual/en/function.shell-exec.php" target="_blank">shell_exec</a> and <a title="system" href="http://www.php.net/manual/en/function.system.php" target="_blank">system</a>. These methods wait for the script to finish and collect the output generated by that script. However, when a user leaves the page, closes his browser or stops the script, the background script which is executed is also stopped. To prevent this, people tend to use other options like <a title="pcntl" href="http://php.net/manual/en/book.pcntl.php" target="_blank">pcnt</a>l or <a title="cURL" href="http://www.php.net/manual/en/book.curl.php" target="_blank">cURL</a>. Using these extensions might offer a solution, but for simply starting a script they are much too verbose.</p>
<p>The solution presented is applicable in the situation where you just need to start a script and you don't want users to be able to stop the script after starting. And the solution is....</p>
<p>The function <a title="ignore_user_abort" href="http://www.php.net/manual/en/function.ignore-user-abort.php" target="_blank">ignore_user_abort()</a>.</p>
<p>By putting this function in front of a shell_exec execution, the script still starts the script executed by shell_exec. However, it doesn't care any more if the user aborts the calling script. In my situation, the CLI script updates a status file and a progress file. When running, the status file contains an integer which denotes that the CLI script is running. This prevents the script from being run again while it's already running. Furthermore, the progress file is updated so the progress can be checked by other scripts.</p>
<p><strong>Source</strong></p>
<p><strong><a href="http://stackoverflow.com/questions/265073/php-background-processes">http://stackoverflow.com/questions/265073/php-background-processes</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/06/starting-a-cli-script-from-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP multidimensional array to plain text tree structure</title>
		<link>http://www.vankouteren.eu/blog/2010/04/php-multidimensional-array-to-plain-text-tree-structure/</link>
		<comments>http://www.vankouteren.eu/blog/2010/04/php-multidimensional-array-to-plain-text-tree-structure/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 12:33:05 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[multidimensional array]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=197</guid>
		<description><![CDATA[Not for the first time I've searched for a way to visualize a multidimensional array in a tree view in my web browser without directly using echo or print. I wasn't able to find a concrete solution for this previously. However, this time I was put on the right track by a post of Kevin [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
<p>Not for the first time I've searched for a way to visualize a multidimensional array in a tree view in my web browser without directly using echo or print. I wasn't able to find a concrete solution for this previously. However, this time I was put on the right track by a post of <a href="http://kevin.vanzonneveld.net/techblog/article/convert_anything_to_tree_structures_in_php/" title="Convert anything to Tree Structures in PHP">Kevin van Zonneveld</a>. <span id="more-197"></span>I've given it my own (quick and dirty as can be seen from the code) twist to get it to work. By just calling:</p>
<p><pre class="brush: php">print implode(ArrayFunctions::toString($array));</pre></p>
<p>The array is shown as a tree structure on the screen.<br />
The implementation is as follows:</p>
<p><pre class="brush: php">&lt;?php
class ArrayFunctions {
  public static function toString($array){
    $result = array();
    $depth = 0;
    foreach($array as $k =&gt; $v) {
            $show_val = ( is_array($v) ? &quot;&quot; : $v );
 
            // show the indents
            $result []= str_repeat(&quot;  &quot;, $depth);
            if($depth == 0) {
                // this is a root node. no parents
                $result []= &quot;O &quot;;
            } elseif(is_array($v)) {
                // this is a normal node. parents and children
                $result []= &quot;+ &quot;;
            } else {
                // this is a leaf node. no children
                $result []= &quot;- &quot;;
            }
 
            // show the actual node
            if ($show_val == &quot;&quot;) {
                $result []= &quot;&lt;strong&gt;{$k}&lt;/strong&gt;:
&quot;;
            }
            else {
                $result []= $k . &quot; (&quot;.$show_val.&quot;)&quot;.&quot;
&quot;;
            }
 
            if(is_array($v)) {
                // this is what makes it recursive, rerun for childs
                $temp = self::toTree($v, ($depth+1));
                foreach($temp as $t) {
                    $result []= $t;
                }
            }
        }
        return implode($result);
    }
 
    private static function showtype($show_val) {
        // convert bools to text and quote 'text bools'!
        if (is_string($show_val) &amp;&amp;
           ($show_val == &quot;true&quot; || $show_val == &quot;false&quot;)) {
            return &quot;\&quot;{$show_val}\&quot;&quot;;
        }
        elseif (is_bool($show_val) &amp;&amp; $show_val === true) {
            return &quot;true&quot;;
        }
        elseif (is_bool($show_val) &amp;&amp; $show_val === false) {
            return &quot;false&quot;;
        }
        elseif (is_null($show_val)) {
            return &quot;null&quot;;
        }
        else {
            return $show_val;
        }
    }
 
    private static function toTree($pieces, $depth = 0) {
        foreach($pieces as $k =&gt; $v) {
            // skip the baseval thingy. Not a real node.
            //if($k == &quot;__base_val&quot;) continue;
            // determine the real value of this node.
            $show_val = ( is_array($v) ? &quot;&quot; : $v );
 
            $show_val = self::showtype($show_val);
 
            // show the indents
            $result []= str_repeat(&quot;  &quot;, $depth);
            if($depth == 0) {
                // this is a root node. no parents
                $result []= &quot;O &quot;;
            } elseif(is_array($v)) {
                // this is a normal node. parents and children
                $result []= &quot;+ &quot;;
            } else {
                // this is a leaf node. no children
                $result []= &quot;- &quot;;
            }
 
            // show the actual node
            if ($show_val == &quot;&quot;) {
                $result []= &quot;&lt;strong&gt;{$k}&lt;/strong&gt;:
&quot;;
            }
            else {
                $result []= $k . &quot;: &lt;i&gt;{$show_val}&lt;/i&gt;
&quot;;
            }
 
            if(is_array($v)) {
                // this is what makes it recursive, rerun for childs
                $temp = self::toTree($v, ($depth+1));
                if (is_array($temp)) {
                    foreach($temp as $t) {
                        $result []= $t;
                    }
                }
                else {
                    $result []= $t;
                }
            }
        }
        return $result;
    }
}
?&gt;</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/04/php-multidimensional-array-to-plain-text-tree-structure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PEAR install on Linux by a n00b for n00bs</title>
		<link>http://www.vankouteren.eu/blog/2010/01/pear-install-on-linux-by-a-n00b-for-n00bs/</link>
		<comments>http://www.vankouteren.eu/blog/2010/01/pear-install-on-linux-by-a-n00b-for-n00bs/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 12:04:23 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webhosting]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[PEAR install]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=186</guid>
		<description><![CDATA[Okay, I must admit: I'm a programmer and I know some commands. Because I want to use PEAR packages, I needed to install it. The installing command is quite easy to find, but I had a hard time determining the directory structure. Some searching on the internet and an IRC conversation (EFNet #pear, thanks davidc_!) [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>Okay, I must admit: I'm a programmer and I know some commands. Because I want to use PEAR packages, I needed to install it. The installing command is quite easy to find, but I had a hard time determining the directory structure. Some searching on the internet and an IRC conversation (EFNet #pear, thanks davidc_!) later I was able to install PEAR in a quite reasonable directory structure.<span id="more-186"></span></p>
<p>Now that all is done it sounds logical. This blogpost is meant for people who want to install PEAR, but are not sure how to do it or about the directories which need to be specified.</p>
<p><strong>Starting install</strong></p>
<p>Log on to your server on the command line (as root). The install acan then be started as follows:</p>
<pre>lynx -source http://pear.php.net/go-pear | php</pre>
<p><strong>Directories</strong></p>
<p>After some questions (which in 99% of the cases just get the default answer), you'll get the prompt for the directories. After adjustment, my structure looks as follows:</p>
<pre>1. Installation prefix ($prefix) : /usr
2. Temporary files directory     : $prefix/temp
3. Binaries directory            : $prefix/bin
4. PHP code directory ($php_dir) : $prefix/share/PEAR
5. Documentation base directory  : $php_dir/docs
6. Data base directory           : $php_dir/data
7. Tests base directory          : $php_dir/tests</pre>
<p><strong>Finishing installation</strong></p>
<p>When the installation is done, the config (php.ini) file can automatically be adjusted. Note that you have to restart apache to load this new config.</p>
<p><strong>The full overview</strong></p>
<p>A complete overview from my PEAR install in- and output is given below.</p>
<p><pre class="brush: cpp">[root@server usr]# lynx -source http://pear.php.net/go-pear | php
Welcome to go-pear!

Go-pear will install the 'pear' command and all the files needed by
it.&Acirc;&nbsp; This command is your tool for PEAR installation and maintenance.

Go-pear also lets you download and install the following optional PEAR
packages: PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2.


If you wish to abort, press Control-C now, or press Enter to continue:

HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none::

Below is a suggested file layout for your new PEAR installation.&Acirc;&nbsp; To
change individual locations, type the number in front of the
directory.&Acirc;&nbsp; Type 'all' to change all of them or simply press Enter to
accept these locations.

1. Installation prefix ($prefix) : /usr
2. Temporary files directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $prefix/temp
3. Binaries directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $prefix/bin
4. PHP code directory ($php_dir) : $prefix/PEAR
5. Documentation base directory&Acirc;&nbsp; : $php_dir/docs
6. Data base directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $php_dir/data
7. Tests base directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $php_dir/tests

1-7, 'all' or Enter to continue: 4
PHP code directory ($php_dir) [$prefix/PEAR] : $prefix/share/PEAR

Below is a suggested file layout for your new PEAR installation.&Acirc;&nbsp; To
change individual locations, type the number in front of the
directory.&Acirc;&nbsp; Type 'all' to change all of them or simply press Enter to
accept these locations.

1. Installation prefix ($prefix) : /usr
2. Temporary files directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $prefix/temp
3. Binaries directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $prefix/bin
4. PHP code directory ($php_dir) : $prefix/share/PEAR
5. Documentation base directory&Acirc;&nbsp; : $php_dir/docs
6. Data base directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $php_dir/data
7. Tests base directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : $php_dir/tests

1-7, 'all' or Enter to continue:
PHP Warning:&Acirc;&nbsp; putenv(): Safe Mode warning: Cannot set environment variable 'TMPDIR' - it's not in the allowed list in /usr/- on line 1264

The following PEAR packages are bundled with PHP: PEAR_Frontend_Web-beta,
PEAR_Frontend_Gtk2, MDB2.
Would you like to install these as well? [Y/n] : n

Loading zlib: ok

Bootstrapping Installer...................
Bootstrapping PEAR.php............(remote) ok
Bootstrapping Archive/Tar.php............(remote) ok
Bootstrapping Console/Getopt.php............(remote) ok

Extracting installer..................
Downloading package: PEAR.............ok
Downloading package: Structures_Graph....ok

Preparing installer..................
Updating channel &quot;doc.php.net&quot;
Update of Channel &quot;doc.php.net&quot; succeeded
Updating channel &quot;pear.php.net&quot;
Update of Channel &quot;pear.php.net&quot; succeeded
Updating channel &quot;pecl.php.net&quot;
Update of Channel &quot;pecl.php.net&quot; succeeded

Installing selected packages..................
Downloading and installing package: PEAR.............warning: pear/PEAR requires package &quot;pear/Archive_Tar&quot; (recommended version 1.3.3)
warning: pear/PEAR requires package &quot;pear/Structures_Graph&quot; (recommended version 1.0.2)
warning: pear/PEAR requires package &quot;pear/Console_Getopt&quot; (recommended version 1.2.3)
warning: pear/PEAR requires package &quot;pear/XML_Util&quot; (recommended version 1.2.1)
downloading PEAR-1.9.0.tgz ...
Starting to download PEAR-1.9.0.tgz (291,634 bytes)
.............................................................done: 291,634 bytes
install ok: channel://pear.php.net/PEAR-1.9.0
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use &quot;pear install pear/PEAR#featurename&quot;
Installing bootstrap package: Structures_Graph.......install ok: channel://pear.php.net/Structures_Graph-1.0.3
Downloading and installing package: Archive_Tar-stable.......downloading Archive_Tar-1.3.5.tgz ...
Starting to download Archive_Tar-1.3.5.tgz (17,184 bytes)
...done: 17,184 bytes
install ok: channel://pear.php.net/Archive_Tar-1.3.5
Downloading and installing package: Console_Getopt-stable.......downloading Console_Getopt-1.2.3.tgz ...
Starting to download Console_Getopt-1.2.3.tgz (4,011 bytes)
...done: 4,011 bytes
install ok: channel://pear.php.net/Console_Getopt-1.2.3

******************************************************************************
WARNING!&Acirc;&nbsp; The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
&amp;lt;/usr/share/PEAR&amp;gt;
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.


Would you like to alter php.ini &amp;lt;/etc/php.ini&amp;gt;? [Y/n] : Y

php.ini &amp;lt;/etc/php.ini&amp;gt; include_path updated.

Current include path&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : .:
Configured directory&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; : /usr/share/PEAR
Currently used php.ini (guess) : /etc/php.ini
Press Enter to continue:

The 'pear' command is now at your service at /usr/bin/pear
[root@server usr]# /etc/init.d/httpd restart
Stopping httpd:&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; [&Acirc;&nbsp; OK&Acirc;&nbsp; ]
Starting httpd:&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp;&Acirc;&nbsp; [&Acirc;&nbsp; OK&Acirc;&nbsp; ]</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/01/pear-install-on-linux-by-a-n00b-for-n00bs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing using WampServer 2: additions</title>
		<link>http://www.vankouteren.eu/blog/2009/12/developing-using-wampserver-2-additions/</link>
		<comments>http://www.vankouteren.eu/blog/2009/12/developing-using-wampserver-2-additions/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 13:42:38 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[WampServer]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=175</guid>
		<description><![CDATA[WampServer 2.0 is a nice tool to help you develop a new site on your local computer. However, you'll probably need more packages/libraries than those included with WampServer. This post is about installing extra common features which are mostly present at hosting servers, but not (directly) on WampServer. PHPUnit One of the features which I [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p><a title="WampServer 2.0" href="http://www.wampserver.com/en/" target="_blank">WampServer 2.0</a> is a nice tool to help you develop a new site on your local computer. However, you'll probably need more packages/libraries than those included with WampServer. This post is about installing extra common features which are mostly present at hosting servers, but not (directly) on WampServer.</p>
<p><span id="more-175"></span></p>
<p><strong>PHPUnit</strong></p>
<p>One of the features which I need when starting a new project is a Unittest framework. The two most common are <a title="SimpleTest" href="http://www.simpletest.org/" target="_blank">SimpleTest</a> and <a title="PHPUnit" href="http://www.phpunit.de/" target="_blank">PHPUnit</a>. SimpleTest can be downloaded and used right away. The <a title="PHPUnit manual" href="http://www.phpunit.de/manual/current/en/installation.html" target="_blank">PHPUnit manual</a> advises to use PEAR to install PHPUnit. <a title="Install PEAR and PHPUnit" href="http://jsdoodnauth.wordpress.com/2008/11/05/installing-wamp-and-phpunit-on-windows/" target="_blank">Joshua Doodnauth</a> explains how to activate PEAR and how to install PHPUnit on WampServer. However, as I was running WampServer 2.0i with PHP 5.3, the file go-pear.phar in the PEAR subdirectory was not working correctly. The solution to this is presented <a title="Install PEAR and PHPUnit on WampServer 2.0 with PHP 5.3" href="http://blog.pear.php.net/2009/07/01/php-53-windows-and-pear/" target="_blank">here</a>. By executing the command</p>
<p><code>php -d phar.require_hash=0 go-pear.phar</code></p>
<p>the problem is solved and PEAR is installed.</p>
<p>After that however, when I tried to get back to Joshua's how-to, the PEAR version was not correct. <a title="Update PEAR" href="http://www.electricmonk.nl/log/2009/04/12/easy-pear-package-creation/" target="_blank">This site</a> helped me to update PEAR. When PEAR is installed, type</p>
<p><code>pear channel-update pear.php.net</code></p>
<p>in the terminal. This will update the PEAR channel. After that, by typing in</p>
<p><code>pear upgrade PEAR</code></p>
<p>the PEAR installation will be updated. From that point on PHPUnit can be installed as described at Joshua's blog.</p>
<p><strong>Crontab</strong></p>
<p>A feature which I use pretty often is the crontab. It can schedule and execute scripts at particular moments. A crontab is not provided by WampServer. However, there are external solutions available. One such solutions is <a title="nnSoft :: nnCron" href="http://www.nncron.ru/" target="_blank">nnCron of nnSoft</a>. This is a crontab which can be installed by executing the installer file. The LITE (free) version already provides the desired functionality. The way it works is pretty simple: in the install directory there are batch files startcron.bat and stopcron.bat which allow to start the crontab and stop it. The file cron.tab contains the <a title="Crontab lines" href="http://www.willmaster.com/library/web-development/using_cron.php" target="_blank">crontab lines</a>.</p>
<p>N.B. Using WampServer and this Crontab, you can write automated tasks in PHP for executing tasks on your local machine. (Nice!).</p>
<p><strong>Mootools</strong></p>
<p>Today I was unpleasantly surprised that Mootools doesn't work on WampServer. I tried various demo's of AJAX calls, but none of them worked. When I tried one on an online web server it worked directly. So far I haven't been able to find topics about this problem, so any help is appreciated!'</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2009/12/developing-using-wampserver-2-additions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FPDF error: Unable to find xref table</title>
		<link>http://www.vankouteren.eu/blog/2009/07/fpdf-error-unable-to-find-xref-table/</link>
		<comments>http://www.vankouteren.eu/blog/2009/07/fpdf-error-unable-to-find-xref-table/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 14:16:34 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[fpdf]]></category>
		<category><![CDATA[fpdi]]></category>
		<category><![CDATA[xref error]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=124</guid>
		<description><![CDATA[Today I faced a problem with FPDF and FPDI when trying to concatenate some PDF files. The only output I got was 'FPDF error: Unable to find xref table.' When I did a search on this error message, I wasn't able to extract the answer from it. After some searching, the problem was located. One of [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>Today I faced a problem with FPDF and <a title="FPDI: concatenate PDF files" href="http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/concatenate-fake/" target="_blank">FPDI when trying to concatenate some PDF files</a>. The only output I got was 'FPDF error: Unable to find xref table.' When I did a search on this error message, I wasn't able to extract the answer from it. After some searching, the problem was located.</p>
<p><span id="more-124"></span></p>
<p>One of the PDFs which should be merged was originally created from Word by a PDF creator which placed its signature in the properties of the PDF document. After removing this signature (in this case opening the PDF with Adobe Illustrator and saving it again) the problem was solved.</p>
<p><strong>Compression and stream<br />
</strong></p>
<p>The FPDF / FPDI classes use the input stream of the PDF file to create the concatenated PDF. Setasign <a title="Setasign remark" href="http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/concatenate-fake/" target="_blank">remarks</a> that the stream is only used (and altered) in the free version. The paid version should not give such errors. As I've experimented with the free version, I'll treat that one here.</p>
<p>Because of compression, some applications might leave out or mess up the xref property. Although this results in a PDF file which can be opened in a PDF reader, the stream is not according to the 'standards'. In such a case the document markup is 'lost' and applications / scripts using this property cannot handle these files any more.</p>
<p><strong>PDF merging code example</strong></p>
<p>To show how PDF files can be merged by using FPDF and FPDI I've compiled a little example which can be downloaded <a title="Downloads" href="http://www.vankouteren.eu/blog/downloads/" target="_self">here</a>. The archive consists of FPDF version 1.6, FPDI version 1.3.1, FPDI_TPL and two sample PDF files which were created with Microsoft Word 2007. The executing script is concat.php. Run this script to concatenate the two sample PDF files together in a new PDF file.</p>
<p><strong>Possible solutions</strong></p>
<p>A paid version of FPDI might be an option, but let's have a look at other possible solutions.</p>
<p>Opening the file and saving it again with a better pdf creator might fix the problem as it reformats the stream which is saved.</p>
<p><strong>Final remarks</strong></p>
<p>When you're creating the source PDF files yourself, watch out which pdf creator you use. Although the visual result might be the same, the stream might not be.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2009/07/fpdf-error-unable-to-find-xref-table/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Working IPv6 regular expression</title>
		<link>http://www.vankouteren.eu/blog/2009/05/working-ipv6-regular-expression/</link>
		<comments>http://www.vankouteren.eu/blog/2009/05/working-ipv6-regular-expression/#comments</comments>
		<pubDate>Fri, 15 May 2009 10:41:02 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[IPv6]]></category>
		<category><![CDATA[IPv6 regex]]></category>
		<category><![CDATA[IPv6 regular expression]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=84</guid>
		<description><![CDATA[Multiple times I've been searching (too long) for a working IPv6 regular expression. There's a lot of crap out of there which doesn't take into account certain cases. Of course you only get to know which one works best if you test them all. I've tried A LOT and finally found the right one As [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>Multiple times I've been searching (too long) for a working IPv6 regular expression. There's a lot of crap out of there which doesn't take into account certain cases. Of course you only get to know which one works best if you test them all. I've tried A LOT and finally found the right one</p>
<p><span id="more-84"></span></p>
<p>As a little reminder for myself, and perhaps a helpful hand for somebody else, if found <a title="Working IPv6 regex" href="http://forums.dartware.com/viewtopic.php?t=452" target="_blank">this page</a> useful and working fine.</p>
<p>The regex itself is:</p>
<pre class="bash">s*<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:|<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>?<span style="color: #7a0874; font-weight: bold;">&#41;</span>|<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>?<span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>?<span style="color: #7a0874; font-weight: bold;">&#41;</span>|<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>?<span style="color: #7a0874; font-weight: bold;">&#41;</span>|<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>?<span style="color: #7a0874; font-weight: bold;">&#41;</span>|<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>?<span style="color: #7a0874; font-weight: bold;">&#41;</span>|<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9A-Fa-f<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>|
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>|<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">-4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>\d|
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">01</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>?\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>%.+<span style="color: #7a0874; font-weight: bold;">&#41;</span>?\s*</pre>
<p>Which, for example in PHP, will become:</p>
<pre class="php"><a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'IPV6_REGEX'</span>, <span style="color: #ff0000;">&quot;/^<span style="color: #000099; font-weight: bold;">\s</span>*((([0-9A-Fa-f]{1,4}:){7}
(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}
(:|((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|
[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})|(:[0-9A-Fa-f]{1,4})))|
(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})
(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})?)|
((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){4}
(:[0-9A-Fa-f]{1,4}){0,1}((:((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})
(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})?)|
((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){3}
(:[0-9A-Fa-f]{1,4}){0,2}((:((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})
(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|
(([0-9A-Fa-f]{1,4}:){2}(:[0-9A-Fa-f]{1,4}){0,3}((:((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|
[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})?)|
((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)(:[0-9A-Fa-f]{1,4}){0,4}
((:((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})?)|
((:[0-9A-Fa-f]{1,4}){1,2})))|(:(:[0-9A-Fa-f]{1,4}){0,5}((:((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|
[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})?)|
((:[0-9A-Fa-f]{1,4}){1,2})))|(((25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})
(<span style="color: #000099; font-weight: bold;">\.</span>(25[0-5]|2[0-4]<span style="color: #000099; font-weight: bold;">\d</span>|[01]?<span style="color: #000099; font-weight: bold;">\d</span>{1,2})){3})))(%.+)?<span style="color: #000099; font-weight: bold;">\s</span>*$/&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2009/05/working-ipv6-regular-expression/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Simple PHP SOAP example</title>
		<link>http://www.vankouteren.eu/blog/2009/03/simple-php-soap-example/</link>
		<comments>http://www.vankouteren.eu/blog/2009/03/simple-php-soap-example/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 10:15:15 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP SOAP example]]></category>
		<category><![CDATA[PHP Web service example]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WSDL file analyzation]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=46</guid>
		<description><![CDATA[This post will show a simple example of how to interpretate a WSDL file and a very simple, yet quick example of how to extract information from this file through PHP. Prior assumptions In this example I assume that you've already have SOAP enabled in your PHP configuration because this is beyond the scope of [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
<p>This post will show a simple example of how to interpretate a WSDL file and a very simple, yet quick example of how to extract information from this file through PHP.</p>
<p><strong>Prior assumptions</strong></p>
<p>In this example I assume that you've already have SOAP enabled in your PHP configuration because this is beyond the scope of this example. If you're not sure, you can check your <a title="How to check your PHP configuration" href="https://support.kayako.com/index.php?_m=knowledgebase&amp;_a=viewarticle&amp;kbarticleid=103&amp;nav=0" target="_blank">phpinfo file</a>. There should be something like this:</p>
<div id="attachment_47" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.vankouteren.eu/blog/wp-content/uploads/2009/03/phpini_soap.jpg"><img class="size-thumbnail wp-image-47" title="SOAP information" src="http://www.vankouteren.eu/blog/wp-content/uploads/2009/03/phpini_soap-150x101.jpg" alt="SOAP information" width="150" height="101" /></a><p class="wp-caption-text">SOAP information</p></div>
<p><span id="more-46"></span></p>
<p><strong>Example WSDL file</strong></p>
<p>For the example WSDL file we'll take <a href="http://footballpool.dataaccess.eu/data/info.wso?wsdl" target="_blank">this WSDL file</a>. It's about the World Championship football 2010 held in South Africa.</p>
<p><strong>Analyzing the WSDL file</strong></p>
<p>Let's analyze this file for a simple method we can call. I usually work with <a title="Notepad++" href="http://notepad-plus.sourceforge.net/" target="_blank">Notepad++</a> or <a title="Smultron" href="http://tuppis.com/smultron/" target="_blank">Smultron</a>. The following line number apply to Notepad++ and probably also to Smulton.</p>
<p>Let's try and print the top goal scorers of the tournament. For doing this, we can see the following on line 1295 - 1300:</p>
<p><pre class="brush: xml">&lt;operation name=&quot;TopGoalScorers&quot;&gt;
  &lt;documentation&gt;
Returns an array with the top N goal scorers and their current score. Pass 0 as TopN and you get them all.
  &lt;/documentation&gt;
  &lt;input message=&quot;tns:TopGoalScorersSoapRequest&quot;/&gt;
  &lt;output message=&quot;tns:TopGoalScorersSoapResponse&quot;/&gt;
&lt;/operation&gt;</pre></p>
<p>We now see that the operation we should call is called <span style="color: #ff0000;">TopGoalScorers</span>. This operation expects as input a <span style="color: #0000ff;">TopGoalScorersSoapRequest</span>. We don't know what it is yet, so let's find out. If we search the document for this message, we get to line 999 - 1002 which says:</p>
<p><pre class="brush: xml">&lt;message name=&quot;TopGoalScorersSoapRequest&quot;&gt;
  &lt;part name=&quot;parameters&quot; element=&quot;tns:TopGoalScorers&quot; /&gt;
&lt;/message&gt;</pre></p>
<p>Right. So now we know that the <span style="color: #0000ff;">TopGoalScorersSoapRequest </span>consists of just one part (the parameters). We know that the element is called <span style="color: #0000ff;">TopGoalScorers</span>, but we do not know anything about this parameter yet. So we search the document for the element <span style="color: #0000ff;">TopGoalScorers</span>. We can find this element at line 384 - 390. These lines say</p>
<p><pre class="brush: xml">&lt;xs:element name=&quot;TopGoalScorers&quot;&gt;
  &lt;xs:complexType&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name=&quot;iTopN&quot; type=&quot;xs:int&quot; /&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
&lt;/xs:element&gt;</pre></p>
<p>Now there we have it: we now finally know that the method <span style="color: #0000ff;">TopGoalScorers </span>which we saw in the first WSDL fragment expects one parameter as input. This parameter is called <span style="color: #ff0000;">iTopN </span>and is of the type <span style="color: #339966;">int</span>.</p>
<p><strong>Getting to the code</strong></p>
<p>Finally we can do something with the WSDL. Actually we can do this in a very short way thanks to the PHP SoapClient!</p>
<p>Calling the service with the parameter and obtaining the results can be done in just 2 lines of code. Let's give it a try and obtain the top 5 goal scorers. We can do this by the following two lines:</p>
<p><pre class="brush: php">$client = new SoapClient(&quot;http://footballpool.dataaccess.eu/data/info.wso?wsdl&quot;);
$result = $client-&gt;TopGoalScorers(array('iTopN'=&gt;5));</pre></p>
<p>Note that we use the information we obtained from the WSDL file here: on the $client object, we call the method <span style="color: #ff0000;">TopGoalScorers </span>and provide an array of parameters. In this case the array contains only one parameter: the <span style="color: #ff0000;">iTopN </span>parameter with an <span style="color: #339966;">int </span>value of 5.</p>
<p>The result will contain an object, so you will need to traverse the object structure.</p>
<p><strong>Choose how much results</strong></p>
<p>There are a lot of possibilities for abstracting such a Web Service call further. I will just give a very simple example file where you can choose how many results you want to see and visualize this in a table.</p>
<p>Code:</p>
<p><pre class="brush: php">&lt;?php

if ($_POST['topn'] &gt; 0 &amp;&amp; (int) $_POST['topn'] &lt;= 20){
  $topn = (int) $_POST['topn'];
  $client = new SoapClient(&quot;http://footballpool.dataaccess.eu/data/info.wso?wsdl&quot;);
  $result = $client-&gt;TopGoalScorers(array('iTopN' =&gt; $topn));
  // Note that $array contains the result of the traversed object structure
  $array = $result-&gt;TopGoalScorersResult-&gt;tTopGoalScorer;

  print &quot;
    &lt;table border='2'&gt;
      &lt;tr&gt;
        &lt;th&gt;Rank&lt;/th&gt;
        &lt;th&gt;Name&lt;/th&gt;
        &lt;th&gt;Goals&lt;/th&gt;
      &lt;/tr&gt;
  &quot;;
  
  foreach($array as $k=&gt;$v){
    print &quot;
      &lt;tr&gt;
        &lt;td align='right'&gt;&quot; . ($k+1) . &quot;&lt;/td&gt;
          &lt;td&gt;&quot; . $v-&gt;sName . &quot;&lt;/td&gt;
          &lt;td align='right'&gt;&quot; . $v-&gt;iGoals . &quot;&lt;/td&gt;
        &lt;/tr&gt;&quot;;
  }
  
  print &quot;&lt;/table&gt;&quot;;
}
else {

?&gt;

  &lt;form id=&quot;topscorers&quot; action=&quot;index.php&quot; method=&quot;post&quot;&gt;
    How long should your topscorers list be? (Choose a digit between 1 and 20).
    &lt;input id=&quot;topn&quot; name=&quot;topn&quot; size=&quot;2&quot; type=&quot;text&quot; value=&quot;10&quot; /&gt;
    &lt;input id=&quot;submit&quot; name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;submit&quot; /&gt;
  &lt;/form&gt;

&lt;?php

}

?&gt;</pre></p>
<p>Note that the form calls <span style="color: #993366;">index.php</span>. This is because I called this script index.php. If you call your script differently, the action should be your script file name. (The reason why I didn't use $_SERVER['PHP_SELF'] is because of <a title="How $_SERVER['PHP_SELF'] can cause an XSS problem" href="http://www.scriptorama.nl/security/tips-veiligere-site-phpself" target="_blank">this</a> Dutch source about how this element can cause an XSS problem).</p>
<p>I hope you found the example useful. If not, let me know! Now go and play with PHP, SOAP and WSDL some more!</p>
<p>Edit 11/08/2010: Noticed that the WSDL was removed. Changed to WC 2010 WSDL file which seems to have the same format as the original WSDL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2009/03/simple-php-soap-example/feed/</wfw:commentRss>
		<slash:comments>93</slash:comments>
		</item>
		<item>
		<title>It&#8217;s been a while</title>
		<link>http://www.vankouteren.eu/blog/2009/01/its-been-a-while/</link>
		<comments>http://www.vankouteren.eu/blog/2009/01/its-been-a-while/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 21:06:00 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[online game]]></category>
		<category><![CDATA[SOAP over HTTPS]]></category>
		<category><![CDATA[Web 3.0]]></category>
		<category><![CDATA[Web services]]></category>
		<category><![CDATA[White Hat Mafia]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=44</guid>
		<description><![CDATA[Seeing the date of my last post I realize that it's been a while ago since I last posted a message, so here's an update. The last couple of months I've been working on my research assignment for the TU Delft which was about data integration and semantics in the context of data warehouses. In [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
<p>Seeing the date of my last post I realize that it's been a while ago since I last posted a message, so here's an update.</p>
<p>The last couple of months I've been working on my research assignment for the <a title="Delft University of Technology" href="http://www.tudelft.nl" target="_blank">TU Delft</a> which was about data integration and semantics in the context of data warehouses. In that research I've analyzed some data warehouses with respect to the current evolving WWW. It seems that especially for the <a title="Web 3.0" href="http://en.wikipedia.org/wiki/Web_3.0" target="_blank">Web 3.0</a> vision Web Services play an important role for interoperability. Next to that online collaboration is a hot topic. As I am a bioinformatician, one of the most important things in this field is security. Currently there's no secure SOAP implementation for a Web service to first establish an SSL connection before sending data. Next to that SSL results in large overhead as it encrypts whole HTTP packages. When having a data warehouse with gigabytes of data this is not practical.</p>
<p><span id="more-44"></span></p>
<p>These are just a few of the things I came along. Later on I will post some more details about them.</p>
<p>Next to that I've been working more on my online game. It's developed pretty cool already, but far from completed. However, I already have claimed my spot on the Web and the name for the game. This will be <a title="White Hat Mafia" href="http://www.whitehatmafia.nl" target="_blank">White Hat Mafia</a>. Although this is in Dutch, I also own the .com domain and my intention is to create the game in such a way that translation is a piece of cake. The current version is 0.2, although version 0.3 is in sight.</p>
<p>So far for now. Gotta catch some sleep as I have got to work tomorrow..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2009/01/its-been-a-while/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

