<?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>Marius van Witzenburg &#187; PHP</title>
	<atom:link href="http://mariusvw.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://mariusvw.com</link>
	<description>We fight for our survival, we fight!</description>
	<lastBuildDate>Tue, 27 Dec 2011 10:35:27 +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>Apache Error Codes</title>
		<link>http://mariusvw.com/2011/11/11/apache-error-codes/</link>
		<comments>http://mariusvw.com/2011/11/11/apache-error-codes/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 15:10:37 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Codes]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=130</guid>
		<description><![CDATA[With the function below you can add your own custom actions to error statuses of Apache. Lets say you want a custom 404 error page. You could redirect a user upon a 404 error or show a complete different layout. /** * HTTP Protocol defined status codes * @param int $num */ function HTTPStatus&#40;$num&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>With the function below you can add your own custom actions to error statuses of Apache.</p>
<p>Lets say you want a custom 404 error page. You could redirect a user upon a 404 error or show a complete different layout.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * HTTP Protocol defined status codes
 * @param int $num
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> HTTPStatus<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   static <span style="color: #000088;">$http</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
       <span style="color: #cc66cc;">100</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 100 Continue&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">101</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 101 Switching Protocols&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">200</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 200 OK&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">201</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 201 Created&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">202</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 202 Accepted&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">203</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 203 Non-Authoritative Information&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">204</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 204 No Content&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">205</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 205 Reset Content&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">206</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 206 Partial Content&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">300</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 300 Multiple Choices&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">301</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 301 Moved Permanently&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">302</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 302 Found&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">303</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 303 See Other&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">304</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 304 Not Modified&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">305</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 305 Use Proxy&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">307</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 307 Temporary Redirect&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">400</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 400 Bad Request&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">401</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 401 Unauthorized&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">402</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 402 Payment Required&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">403</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 403 Forbidden&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">404</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 404 Not Found&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">405</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 405 Method Not Allowed&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">406</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 406 Not Acceptable&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">407</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 407 Proxy Authentication Required&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">408</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 408 Request Time-out&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">409</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 409 Conflict&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">410</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 410 Gone&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">411</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 411 Length Required&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">412</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 412 Precondition Failed&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">413</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 413 Request Entity Too Large&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">414</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 414 Request-URI Too Large&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">415</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 415 Unsupported Media Type&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">416</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 416 Requested range not satisfiable&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">417</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 417 Expectation Failed&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">500</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 500 Internal Server Error&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">501</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 501 Not Implemented&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">502</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 502 Bad Gateway&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">503</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 503 Service Unavailable&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #cc66cc;">504</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;HTTP/1.1 504 Gateway Time-out&quot;</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$http</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You can download this <a href="http://kitara.nl/wp-content/uploads/2011/06/404.zip">404 error page example</a> to play with.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/11/11/apache-error-codes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Performance &#8211; isset() versus empty() versus PHP Notices</title>
		<link>http://mariusvw.com/2011/07/17/php-performance-isset-versus-empty-versus-php-notices/</link>
		<comments>http://mariusvw.com/2011/07/17/php-performance-isset-versus-empty-versus-php-notices/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 14:01:14 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Empty]]></category>
		<category><![CDATA[Isset]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=217</guid>
		<description><![CDATA[I’m cleaning up a lot of PHP code and always program with PHP error_reporting set to E_ALL and display_errors turned on so that I make sure to catch any PHP messages that come up. Since starting on this site, I have fixed literally hundreds (maybe thousands) of PHP Notices about using uninitialized variables and non-existent [...]]]></description>
			<content:encoded><![CDATA[<p>I’m cleaning up a lot of PHP code and always program with PHP error_reporting set to E_ALL and display_errors turned on so that I make sure to catch any PHP messages that come up. Since starting on this site, I have fixed literally hundreds (maybe thousands) of PHP Notices about using uninitialized variables and non-existent array indexes.</p>
<p>I have been fixing problems like this where $somevar is sometimes undefined:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$somevar</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>by changing it to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$somevar</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$somevar</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>This successfully gets rid of the NOTICEs, but adds some overhead because PHP has to perform two checks. After fixing a lot of this in this manner, I’ve noticed that the pages seem to be generated a little slower.</p>
<p>So, to provide some conclusive results to myself, I wrote up a quick benchmarking script - available at <a href="http://www.brandonchecketts.com/downloads/php_empty_benchmark.php">php_empty_benchmark.php</a>. It goes through 1,000,000 tests using each of these methods:</p>
<ol>
<li>if ($a) - This generates a notice if $a is not set</li>
<li>if (isset($a)) - A simple clean way to check if the variable is set (note that it is not equivalent to the one above)</li>
<li>if (isset($a) &amp;&amp; ($a) - The one that I have been using which is equivalent to if($a), but doesn’t generate a notice.</li>
<li>if (!empty($a)) - This is functionally equivalent to if($a), but doesn’t generate a notice.</li>
</ol>
<p>It measures the time to perform 1 million tests using a defined percentage of values that are set.  It then computes the difference as a percentage of the time taken for the original test (the one that generates the notices).   A ‘diff’ of 100 means that the execution time is the same, greater than 100 means that it is faster, and less than 100 means that it is slower. A typical test produced these results:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">With NOTICE: 0.19779300689697
With isset:  0.19768500328064 / Diff: 100.05463419811
With both:   0.21704912185669 / Diff: 91.128222590815
With !empty: 0.19779801368713 / Diff: 99.997468735875</pre></div></div>

<p>In summary, using the if (isset($a) &amp;&amp; $a) syntax is about 8-10% slower than generating the PHP Notice. Using !empty() should be a drop-in replacement that doesn’t generate the notice and has virtually no performance impact. Using ifset() also has no performance impact, but is not exactly the same as ‘if($a)’ since isset() will return true if the variable is set to a false value. I included it here, because it often make the code a little more readable than the !empty($a) syntax. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myvalue</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'myvalue'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'myvalue'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></div></div>

<p>Versus</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myvalue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'myvalue'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'myvalue'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></div></div>

<p>Source:<br />
<a href="http://www.brandonchecketts.com/archives/php-performance-isset-versus-empty-versus-php-notices">http://www.brandonchecketts.com/archives/php-performance-isset-versus-empty-versus-php-notices</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/17/php-performance-isset-versus-empty-versus-php-notices/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to check if a key exists in an array with in_array for Bash</title>
		<link>http://mariusvw.com/2011/07/17/how-to-check-if-a-key-exists-in-an-array-with-in_array-for-bash/</link>
		<comments>http://mariusvw.com/2011/07/17/how-to-check-if-a-key-exists-in-an-array-with-in_array-for-bash/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 13:34:16 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[in_array]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=221</guid>
		<description><![CDATA[When working with Bash it might become handy to have a way to check if a record exists in an array. In PHP you have in_array for this... The below code adds a function similar to the PHP variant. function in_array&#40;&#41; &#123; local x ENTRY=$1 shift 1 ARRAY=&#40; &#34;$@&#34; &#41; &#91; -z &#34;${ARRAY}&#34; &#93; &#38;&#38; [...]]]></description>
			<content:encoded><![CDATA[<p>When working with Bash it might become handy to have a way to check if a record exists in an array. In PHP you have <a href="http://www.php.net/in_array">in_array</a> for this... The below code adds a function similar to the PHP variant.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> in_array<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> x
  <span style="color: #007800;">ENTRY</span>=<span style="color: #007800;">$1</span>
  <span style="color: #7a0874; font-weight: bold;">shift</span> <span style="color: #000000;">1</span>
  <span style="color: #007800;">ARRAY</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #ff0000;">&quot;$@&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ARRAY}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ENTRY}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
  <span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${ARRAY[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${x}</span>&quot;</span> == <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ENTRY}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
  <span style="color: #000000; font-weight: bold;">done</span>
  <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">MASTER</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">CURRENT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">FIRST</span>=<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">for</span> SERVER <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${SERVERS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #666666; font-style: italic;"># collect all builds from server and populate CURRENT list</span>
  <span style="color: #007800;">COMMAND</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${LS}</span> -1fd <span style="color: #007800;">${WEBROOT}</span>/<span style="color: #007800;">${SITE}</span>.*&quot;</span>
  <span style="color: #007800;">BUILDS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #800000;">${SSH}</span> <span style="color: #800000;">${SSHOPTS}</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${SERVER}</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${COMMAND}</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #000000; font-weight: bold;">for</span> BUILD <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${BUILDS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #007800;">CURRENT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${CURRENT[@]-}</span> <span style="color: #800000;">${BUILD}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># if this is our first time around, copy CURRENT to MASTER</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${FIRST}</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">MASTER</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${CURRENT[@]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #007800;">FIRST</span>=<span style="color: #000000;">0</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># now we do a compare between MASTER and CURRENT to see what builds</span>
  <span style="color: #666666; font-style: italic;"># are common</span>
  <span style="color: #007800;">INTERSECT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">for</span> ENTRY <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${CURRENT[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    in_array <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ENTRY}</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MASTER[@]}</span>&quot;</span>
    <span style="color: #007800;">RET</span>=<span style="color: #007800;">$?</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${RET}</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #007800;">INTERSECT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${INTERSECT[@]-}</span> <span style="color: #800000;">${ENTRY}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #000000; font-weight: bold;">done</span>
  <span style="color: #007800;">MASTER</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${INTERSECT[@]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># clear the CURRENT array</span>
  <span style="color: #007800;">CURRENT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Source: <a href="http://mykospark.net/tag/in_array/">http://mykospark.net/tag/in_array/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/17/how-to-check-if-a-key-exists-in-an-array-with-in_array-for-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to modify HTTP headers with PHP header() function</title>
		<link>http://mariusvw.com/2011/07/13/how-to-modify-http-headers-with-php-header-function/</link>
		<comments>http://mariusvw.com/2011/07/13/how-to-modify-http-headers-with-php-header-function/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 11:57:21 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Header]]></category>
		<category><![CDATA[Http]]></category>
		<category><![CDATA[Modify]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=6287</guid>
		<description><![CDATA[Many examples that show how to use the header() function of PHP. Hint: If you want to check your headers, you can use web based tools like: web-sniffer.net, web-browser extensions (e.g. LiveHTTPHeaders, ieHTTPHeaders) or another third-party software tool. // See related links for more status codes &#160; // Use this header instruction to fix 404 [...]]]></description>
			<content:encoded><![CDATA[<p>Many examples that show how to use the header() function of PHP.</p>
<p><strong>Hint:</strong><br />
If you want to check your headers, you can use web based tools like: <a href="http://web-sniffer.net/">web-sniffer.net</a>, web-browser extensions (e.g. <a href="http://livehttpheaders.mozdev.org/">LiveHTTPHeaders</a>, <a href="http://www.blunck.se/iehttpheaders/iehttpheaders.html">ieHTTPHeaders</a>) or another third-party software tool.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// See related links for more status codes</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use this header instruction to fix 404 headers</span>
<span style="color: #666666; font-style: italic;">// produced by url rewriting...</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 200 OK'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Page was not found:</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 404 Not Found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Access forbidden:</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 403 Forbidden'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The page moved permanently should be used for</span>
<span style="color: #666666; font-style: italic;">// all redrictions, because search engines know</span>
<span style="color: #666666; font-style: italic;">// what's going on and can easily update their urls.</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 301 Moved Permanently'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Server error</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 500 Internal Server Error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Redirect to a new location:</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: http://www.example.org/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Redriect with a delay:</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Refresh: 10; url=http://www.example.org/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'You will be redirected in 10 seconds'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// you can also use the HTML syntax:</span>
<span style="color: #666666; font-style: italic;">// &lt;meta http-equiv=&quot;refresh&quot; content=&quot;10;http://www.example.org/ /&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// override X-Powered-By value</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'X-Powered-By: PHP/4.4.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'X-Powered-By: Brain/0.6b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// content language (en = English)</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-language: en'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// last modified (good for caching)</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// or filemtime($fn), etc</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Last-Modified: '</span><span style="color: #339933;">.</span><span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' GMT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// header for telling the browser that the content</span>
<span style="color: #666666; font-style: italic;">// did not get changed</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 304 Not Modified'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// set content length (good for caching):</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Length: 1234'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Headers for an download:</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/octet-stream'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;example.zip&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Transfer-Encoding: binary'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// load the file to send:</span>
<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'example.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Disable caching of the current document:</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cache-Control: no-cache, no-store, max-age=0, must-revalidate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Expires: Mon, 26 Jul 1997 05:00:00 GMT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Date in the past</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pragma: no-cache'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// set content type:</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: text/html; charset=iso-8859-1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: text/html; charset=utf-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// plain text file</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/jpeg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// JPG picture</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ZIP file</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/pdf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// PDF file</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: audio/mpeg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Audio MPEG (MP3,...) file</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/x-shockwave-flash'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Flash animation</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// show sign in box</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 401 Unauthorized'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WWW-Authenticate: Basic realm=&quot;Top Secret&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'Text that will be displayed if the user hits cancel or '</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'enters wrong login data'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Source: <a href="http://www.jonasjohn.de/snippets/php/headers.htm">http://www.jonasjohn.de/snippets/php/headers.htm</a></p>
<p>Related links:<br />
<a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">http://en.wikipedia.org/wiki/List_of_HTTP_status_codes</a><br />
<a href="http://www.web-caching.com/mnot_tutorial/">http://www.web-caching.com/mnot_tutorial/</a><br />
<a href="http://www.web-caching.com/mnot_tutorial/">http://reeg.junetz.de/DSP/node16.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/13/how-to-modify-http-headers-with-php-header-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to generate a .htaccess and .htpasswd with PHP</title>
		<link>http://mariusvw.com/2011/07/06/how-to-generate-a-htaccess-and-htpasswd-with-php/</link>
		<comments>http://mariusvw.com/2011/07/06/how-to-generate-a-htaccess-and-htpasswd-with-php/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 10:23:12 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=346</guid>
		<description><![CDATA[Ever had a moment where you needed to secure a directory but didn't have the htpasswd tool available? The following script simply generates a .htaccess and .htpasswd file to secure a directory. &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;body&#62; &#60;?php if &#40;!empty&#40;$_POST&#91;'username'&#93;&#41; &#38;&#38; !empty&#40;$_POST&#91;'password'&#93;&#41;&#41;: ?&#62; &#60;strong&#62;.htaccess&#60;/strong&#62;&#60;br&#62; &#60;pre&#62; AuthName &#34;Members only&#34; AuthType Basic AuthUserFile /srv/www/domain.tld/.htpasswd require valid-user &#60;/pre&#62; Save [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had a moment where you needed to secure a directory but didn't have the htpasswd tool available?</p>
<p>The following script simply generates a .htaccess and .htpasswd file to secure a directory.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;strong&gt;.htaccess&lt;/strong&gt;&lt;br&gt;
&lt;pre&gt;
AuthName &quot;Members only&quot;
AuthType Basic
AuthUserFile /srv/www/domain.tld/.htpasswd
require valid-user
&lt;/pre&gt; 
Save the above file in the directory you want to secure.&lt;br&gt;
&lt;br&gt;
&lt;strong&gt;.htpasswd&lt;/strong&gt;&lt;br&gt;
&lt;pre&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/pre&gt;
Save the above file as &lt;strong&gt;/srv/www/domain.tld/.htpasswd&lt;/strong&gt;.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&amp;laquo; BACK &amp;laquo;&lt;/a&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form method=&quot;post&quot;&gt;
Username: &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;&lt;br&gt;
Password: &lt;input type=&quot;text&quot; name=&quot;password&quot;&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot;&gt;
&lt;/form&gt;
&lt;/form&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/06/how-to-generate-a-htaccess-and-htpasswd-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to generate a Windows Live Messenger or MSN Messenger contactlist file with PHP</title>
		<link>http://mariusvw.com/2011/07/04/how-to-generate-a-windows-live-messenger-or-msn-messenger-contactlist-file-with-php/</link>
		<comments>http://mariusvw.com/2011/07/04/how-to-generate-a-windows-live-messenger-or-msn-messenger-contactlist-file-with-php/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 18:46:20 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Contacts]]></category>
		<category><![CDATA[Generate]]></category>
		<category><![CDATA[Live]]></category>
		<category><![CDATA[Messenger]]></category>
		<category><![CDATA[MSN]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=6027</guid>
		<description><![CDATA[If you would like to generate a contact list with PHP to import email addresses into your contact list use the following... PHP contactlist generator mysql_connect&#40;'localhost', 'username', 'password'&#41;; mysql_select_db&#40;'database'&#41;; &#160; $doc = new DOMDocument&#40;'1.0'&#41;; $doc-&#62;formatOutput = true; &#160; $node = $doc-&#62;createElement&#40;'messenger'&#41;; $messenger = $doc-&#62;appendChild&#40;$node&#41;; &#160; $node = $doc-&#62;createElement&#40;'service'&#41;; $node-&#62;setAttribute&#40;'name', '.NET Messenger Service'&#41;; $service = $messenger-&#62;appendChild&#40;$node&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>If you would like to generate a contact list with PHP to import email addresses into your contact list use the following...</p>
<h2>PHP contactlist generator</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatOutput</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'messenger'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$messenger</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'service'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.NET Messenger Service'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$service</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$messenger</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contactlist'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$contactlist</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$service</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `email` FROM `contacts`&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$contactlist</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=contacts.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Output</h2>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;messenger<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;.NET Messenger Service&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contactlist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>email1@domain.tld<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>email2@domain.tld<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>email3@domain.tld<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>email4@domain.tld<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>email5@domain.tld<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/contact<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/contactlist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/messenger<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/04/how-to-generate-a-windows-live-messenger-or-msn-messenger-contactlist-file-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some useful information about PHP RegEx</title>
		<link>http://mariusvw.com/2011/07/02/some-useful-information-about-php-regex/</link>
		<comments>http://mariusvw.com/2011/07/02/some-useful-information-about-php-regex/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 10:04:57 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Grep]]></category>
		<category><![CDATA[Match]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Preg]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Replace]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=5961</guid>
		<description><![CDATA[This information can be handy with the following PHP functions: * preg_filter * preg_grep * preg_last_error * preg_match_all * preg_match * preg_quote * preg_replace_callback * preg_replace * preg_split What is a regex? At its most basic level, a regex can be considered a method of pattern matching or matching patterns within a string. In PHP [...]]]></description>
			<content:encoded><![CDATA[<p>This information can be handy with the following PHP functions:<br />
  * preg_filter<br />
  * preg_grep<br />
  * preg_last_error<br />
  * preg_match_all<br />
  * preg_match<br />
  * preg_quote<br />
  * preg_replace_callback<br />
  * preg_replace<br />
  * preg_split</p>
<h2>What is a regex?</h2>
<p>At its most basic level, a regex can be considered a method of pattern matching or matching patterns within a string. In PHP the most oft used is PCRE or "Perl Compatible Regular Expressions". Here we will try to decypher the meaningless hieroglyphics and set you on your way to a powerful tool for use in your applications. Do not try to understand all this in a single sitting. Instead, take in a little and come back as you grasp various concepts.</p>
<h2>Where do I begin?</h2>
<p>At the beginning.</p>
<p>Lets create a string.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// echo our string</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If we simply wanted to see if the pattern 'abc' was within our larger string we could easily do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/abc/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The code above will echo '1'. This is because it has found 1 match for the regex. That means it has found the pattern 'abc' once in the larger string. [[http://www.php.net/preg-match|preg_match()]] will count zero if there is no matches, or one if it finds a match. This function will stop searching after the first match. Of course, you would not do this in a real world situation as php has functions for this such as [[http://www.php.net/strpos|strpos()]] and [[http://www.php.net/strstr|strstr()]] which will do this much faster.</p>
<h2>Match beginning of a string</h2>
<p>Now we wish to see if the string begins with abc. The regex character for beginning is the caret ^. To see if our string begins with abc, we use it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match the beginning of the string</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^abc/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if it matches we echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string begins with abc'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if no match is found echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>From the code above we see that it echo's the line ''The string begins with abc''. The forward slashes are a delimeter that hold our regex pattern. The quotations are used to 'wrap it all up'. So we see that using the caret(^) will give us the beginning of the string, but NOT whatever is after it.</p>
<h2>What if I want case insensitive?</h2>
<p>If you used the above code to find the pattern ABC like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^ABC/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>the script would have returned the message:</p>
<p>No match found</p>
<p>This is because the search is case sensitive. The pattern 'abc' is not the same as 'ABC'. To match both 'abc' and 'ABC' we need to use a modifier to make the search case in-sensitive. With php regex, like most regex, is use 'i' for insensitive. So now our script might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match our pattern</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^ABC/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// echo this is it matches</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string begins with abc'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if not match is found echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now the script will find the pattern abc. It would also match any case in-sensitive combination of abc, ABC, Abc, aBc, and so on.</p>
<p>More on [[http://php.net/manual/en/reference.pcre.pattern.modifiers.php|modifiers]] later.</p>
<h2>How do I find a pattern at the end of a string?</h2>
<p>This is done in much the same way as with finding a a pattern at the beginning of a string. A common mistake made by many is to use the $ character to match the end of a string. This is incorrect and \z should be used. Consider this..</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^foo$/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;foo<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>This will return true as $ is like \Z which is like (?=\z|\n\z). So when a newline is not wanted, $ should not be used. Also $ will match multiple times with the /m modifier whereas \z will not. Lets make a small change to the code from above by removing the caret(^) at the beginning of the pattern and putting \z at the end of the pattern, we will keep the case in-sensitive modifier in to match any case.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match our pattern at the end of the string</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/89\z/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if our pattern matches we echo this </span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string ends with 89'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if no match is found we echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The script now will show the line<br />
''The string ends with 89''<br />
because we have matched the end of the string with the pattern 89. Pretty easy stuff so far.</p>
<h2>Meta characters</h2>
<p>During our first look at regex we did some simple pattern matching. We also introduced the caret(^) and the dollar($). These characters have special meaning. As we saw, the caret(^) matched the beginning of a string and the dollar matched the end of a string. These characters, along with others are called Meta characters. Here is a list of the Meta characters used for regex:<br />
  * . (Full stop)<br />
  * ^ (Carat)<br />
  * * (Asterix)<br />
  * + (Plus)<br />
  * ? (Question Mark)<br />
  * { (Opening curly brace)<br />
  * [ (Opening brace)<br />
  * ] (Closing brace)<br />
  * \ (Backslash)<br />
  * | (Pipe)<br />
  * ( (Opening parens)<br />
  * ) (Closing parens)<br />
  * } (Closing curly brace)<br />
We will look at each of these during this tutorial, but it is important that you know what they are. If you wish to search a string that contains one of these characters, eg: "1+1" then you need to escape the the meta character with a backslash like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1+1=2'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match our pattern</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^1\+1/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if the pattern matches we echo this</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string begins with 1+1'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if no match is found we echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>From the code above you will see the script print:<br />
''The string begins with 1+1''<br />
because it found the pattern 1+1 and ignored or escaped the special meaning of the + symbol. If you were to not escape the meta character and use the regex</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^1+1/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>you would not find a match.<br />
If you are looking for a backslash, you need to escape that also. But, we also need to escape the control character too, which is itself a backslash, hence we need to escape twice like this</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">\\\\</pre></div></div>

<h2>What do the other Meta characters do?</h2>
<p>We have already seen the caret **^** and the dollar **$** in action, so now lets look at the others, beginning with the square braces [ ]. These Meta characters are used for specifying a character class.</p>
<p>A what?</p>
<p>A Character Class. This is just a set of characters you wish to match. They can be listed individually like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[abcdef]</pre></div></div>

<p>or as a range seperated by a **-** symbol like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[a-f]</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'big'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Search for a match</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/b[aoiu]g/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Source: <a href="http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html">http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/02/some-useful-information-about-php-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to recursive delete files and directories with PHP</title>
		<link>http://mariusvw.com/2011/07/02/how-to-recursive-delete-files-and-directories-with-php/</link>
		<comments>http://mariusvw.com/2011/07/02/how-to-recursive-delete-files-and-directories-with-php/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 08:53:19 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Delete]]></category>
		<category><![CDATA[Directories]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[Remove]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=5956</guid>
		<description><![CDATA[This is an example how you could recursive delete directories with PHP. Keep in mind that you ALWAYS define a root where this function should do its action. This can seriously remove all your files. define&#40;'UPLOADFILES', dirname&#40;dirname&#40;__FILE__&#41;&#41; . '/uploadfiles'&#41;; &#160; function recursiveDelete&#40;$path&#41; &#123; if &#40;strpos&#40;$path, UPLOADFILES&#41; === false&#41; &#123; exit&#40;'Trying to remove from wrong path [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example how you could recursive delete directories with PHP.</p>
<p>Keep in mind that you ALWAYS define a root where this function should do its action.</p>
<p>This can seriously remove all your files.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'UPLOADFILES'</span><span style="color: #339933;">,</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/uploadfiles'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> recursiveDelete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span> UPLOADFILES<span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Trying to remove from wrong path to uploadfiles!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$objects</span> <span style="color: #339933;">=</span> <span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$objects</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$object</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'..'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				recursiveDelete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$objects</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">rmdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/02/how-to-recursive-delete-files-and-directories-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to send a message to your iPhone via Pushme.to with PHP or Bash and Curl</title>
		<link>http://mariusvw.com/2011/06/14/how-to-send-a-message-to-your-iphone-via-pushme-to-with-php-or-bash-and-curl/</link>
		<comments>http://mariusvw.com/2011/06/14/how-to-send-a-message-to-your-iphone-via-pushme-to-with-php-or-bash-and-curl/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 12:05:21 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Curl]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[GEOM]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Pushme]]></category>
		<category><![CDATA[S.M.A.R.T.]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[SMS]]></category>
		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=241</guid>
		<description><![CDATA[After having Pushme.to installed on my iPhone for over 3 months now I finally had the time to work on some scrips to make it work in different languages for use on servers that I manage. The PHP version is the less version I use but may be handy for some people. PHP Version: function [...]]]></description>
			<content:encoded><![CDATA[<p>After having <a href="http://pushme.to/">Pushme.to</a> installed on my <a href="http://www.apple.com/iphone/">iPhone</a> for over 3 months now I finally had the time to work on some scrips to make it work in different languages for use on servers that I manage.</p>
<p>The <a href="http://php.net/">PHP</a> version is the less version I use but may be handy for some people.</p>
<p><strong>PHP Version</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> pushMeTo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$signature</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://pushme.to/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">'message='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;signature='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$signature</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
pushMeTo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Hello world!'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'God'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A more used version is the commandline (<a href="http://www.gnu.org/software/bash/">Bash</a>) version:</p>
<p><strong>Bash version</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">username</span>=<span style="color: #ff0000;">&quot;username&quot;</span>
<span style="color: #007800;">message</span>=<span style="color: #ff0000;">&quot;Hello world&quot;</span>
<span style="color: #007800;">signature</span>=<span style="color: #ff0000;">&quot;God&quot;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>curl <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;message=<span style="color: #007800;">$message</span>&quot;</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;signature=<span style="color: #007800;">$signature</span>&quot;</span> <span style="color: #ff0000;">&quot;http://pushme.to/<span style="color: #007800;">$username</span>/&quot;</span></pre></div></div>

<p>I currently use these for server monitoring on <a href="http://www.freebsd.org/">FreeBSD</a> like the <a href="http://www.freebsd.org/doc/handbook/geom.html">GEOM</a> Raid bay and <a href="http://en.wikipedia.org/wiki/S.M.A.R.T.">S.M.A.R.T.</a> status of the disks and website monitoring which works quite nice. And in case the internet connection drops I have a backup via <a href="http://en.wikipedia.org/wiki/SMS">SMS</a> with a serial connected cellphone. So this should be quite failsafe <img src='http://mariusvw.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If you have any other language that you want to use such as <a href="http://www.perl.org/">Perl</a> just let me know and I could write it for you.</p>
<p>I hope you find these scripts useful. Happy texting! <img src='http://mariusvw.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/06/14/how-to-send-a-message-to-your-iphone-via-pushme-to-with-php-or-bash-and-curl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Download Redtube movies with a simple PHP class</title>
		<link>http://mariusvw.com/2011/06/14/download-redtube-movies-with-a-simple-php-class/</link>
		<comments>http://mariusvw.com/2011/06/14/download-redtube-movies-with-a-simple-php-class/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 11:52:07 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Movies]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Porn]]></category>
		<category><![CDATA[Redtube]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=227</guid>
		<description><![CDATA[For donations I build everything... Simply put this file on a server where you want and start downloading class RedTube &#123; function form&#40;&#41; &#123; echo '&#60;form method=&#34;post&#34;&#62;&#60;input type=&#34;text&#34; name=&#34;url&#34;&#62;&#60;input type=&#34;submit&#34;&#62;&#60;/form&#62;'; &#125; &#160; function download&#40;$url = null&#41; &#123; if &#40;$this-&#62;validate&#40;$url&#41;&#41; &#123; $content = $this-&#62;fetch&#40;$url&#41;; &#160; preg_match&#40;'#&#60;h1 class=&#34;videoTitle&#34;&#62;(.*)&#60;/h1&#62;#', $content, $d1&#41;; //preg_match('#&#60;source src=\'(.*)\' type=\\\&#34;video/mp4\\\&#34;&#62;#', $content, $d2); preg_match&#40;'#&#60;source src=\'(.*)\' [...]]]></description>
			<content:encoded><![CDATA[<p>For donations I build everything...</p>
<p>Simply put this file on a server where you want and start downloading <img src='http://mariusvw.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> RedTube <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;form method=&quot;post&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;url&quot;&gt;&lt;input type=&quot;submit&quot;&gt;&lt;/form&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> download<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#&lt;h1 class=&quot;videoTitle&quot;&gt;(.*)&lt;/h1&gt;#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">//preg_match('#&lt;source src=\'(.*)\' type=\\\&quot;video/mp4\\\&quot;&gt;#', $content, $d2);</span>
            <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#&lt;source src=\'(.*)\' type=\'video/mp4\'&gt;#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: application/octet-stream&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.mp4'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>       
        <span style="color: #009900;">&#125;</span>       
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> validate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^http://(www.)?redtube.com/[0-9]+$#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>       
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> fetch<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stream</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>       
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>       
            <span style="color: #009900;">&#125;</span>       
            <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>       
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$rt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RedTube<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$rt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">download</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$rt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/06/14/download-redtube-movies-with-a-simple-php-class/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

