<?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/"
	>

<channel>
	<title>Arpad Ray</title>
	<atom:link href="http://arpad.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://arpad.co.uk</link>
	<description>Est. 1984</description>
	<pubDate>Sat, 14 Mar 2009 14:12:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fu**ing numeric ranges in regex</title>
		<link>http://arpad.co.uk/2009/03/numeric-ranges-in-regex/</link>
		<comments>http://arpad.co.uk/2009/03/numeric-ranges-in-regex/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 20:40:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Featured]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arpadblog.local/?p=135</guid>
		<description><![CDATA[A question I hear quite frequently is, how do you match a number within a range in a regular expression? This is a pretty odd question, since regular expressions tend to deal with strings without worrying about the meaning of their content. Most of the time it turns out the person asking is trying to do <em>all</em> of their input validation using regular expressions, which I believe is a singularly bad idea.]]></description>
			<content:encoded><![CDATA[<a href="http://arpad.co.uk/2009/03/numeric-ranges-in-regex/" title="Fu**ing numeric ranges in regex"><img src="http://arpad.co.uk/wp-content/uploads/yapb_cache/range.1am7yhqmgspwwc4cgs0osc0s8.a9sxxja1njksswcs400wcc4cg.th.jpeg" width="180" height="98" alt="Fu**ing numeric ranges in regex" style="float:left;padding:0 10px 10px 0;" ></a><p>A question I hear quite frequently is, how do you match a number within a range in a regular expression? This is a pretty odd question, since regular expressions tend to deal with strings without worrying about the meaning of their content. Most of the time it turns out the person asking is trying to do <em>all</em> of their input validation using regular expressions, which I believe is a singularly bad idea.</p>
<p>Here's an example of what I'm talking about, to match an integer between 0 and 255 (like an octet of an IP address) we could use the following pattern:</p>
<pre>
25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9]?
</pre>
<p>For the pragmatists out there, one arguably valid use case is searching log files for lines about a particular subnet. Anyway, I think that this is an interesting enough problem to tackle without worrying much about practical applications.</p>
<p>About a year ago I came across <a href="http://weblogs.asp.net/justin_rogers/">Justin Rogers'</a> solution to this very problem in C#. As much as I admire his coding skills, his solution seemed to me rather verbose and heavy with special cases. I thought I could do better, or at least understand better how he ended up with that solution by tackling it myself.</p>
<p>I started by writing around 20 test cases, then porting his solution to PHP, so I would have a reference implementation to check my tests against. It took me a while to come up with my own working version, but I was happy to see it passing the carefully crafted tests. I was even happier that it was a fraction of the size of the reference implementation with no special cases to mar its elegance.</p>
<p>However I had a nasty surprise after adding a couple more tests, my solution mysteriously failed them. Evidently my hand written test cases (as usual, some random and some boundary counditions) weren't comprehensive enough. It took me quite a while to find general fixes, but then my happiness returned for a brief visit.</p>
<p>To quell a worry, I decided to generate a hundred more random test cases, AKA. <a href="http://en.wikipedia.org/wiki/Fuzz_testing">fuzzing</a>. Inevitably more failures emerged, about ten of the new tests failed.</p>
<p>With a decent number of test runs to study, it was quickly apparent that the major issue lay with ranges of the same length which shared a common prefix, e.g. 223-229. My limited test cases from before had led me in the wrong direction.</p>
<p>Eventually I had one failing test out of about 120, which illuminated a subtle error in the logic. After fixing that I ran the code against 50,000 more randomly generated test cases, and was finally assured that it was working.</p>
<p>The code below, I can quite confidently say, works fine. If you find a bug in it then please send me a self-addressed machete so I can thank you properly.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="kw2">function</span> generateRange<span class="br0">&#40;</span><span class="re0">$min</span><span class="sy0">,</span> <span class="re0">$max</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    <span class="re0">$digit</span> <span class="sy0">=</span> <span class="st_h">'[0-9]'</span><span class="sy0">;</span>
    <span class="re0">$lenMax</span> <span class="sy0">=</span> <span class="kw3">strlen</span><span class="br0">&#40;</span><span class="re0">$max</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$lenMin</span> <span class="sy0">=</span> <span class="kw3">strlen</span><span class="br0">&#40;</span><span class="re0">$min</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$lenDiff</span> <span class="sy0">=</span> <span class="re0">$lenMax</span> <span class="sy0">-</span> <span class="re0">$lenMin</span><span class="sy0">;</span>
    <span class="re0">$min</span> <span class="sy0">=</span> <span class="kw3">str_pad</span><span class="br0">&#40;</span><span class="re0">$min</span><span class="sy0">,</span> <span class="re0">$lenMax</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> STR_PAD_LEFT<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$max</span> <span class="sy0">=</span> <span class="br0">&#40;</span>string<span class="br0">&#41;</span><span class="re0">$max</span><span class="sy0">;</span>
&nbsp;
    <span class="co1">// find length of common prefix</span>
    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="re0">$i</span> <span class="sy0">&lt;</span> <span class="re0">$lenMin</span> <span class="sy0">&amp;&amp;</span> <span class="re0">$min</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span> <span class="sy0">==</span> <span class="re0">$max</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span> <span class="re0">$i</span><span class="sy0">++</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$prefixLength</span> <span class="sy0">=</span> <span class="re0">$i</span><span class="sy0">;</span>
&nbsp;
    <span class="co1">// add non-conflicting ranges from each end</span>
    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">=</span> <span class="re0">$lenMax</span><span class="sy0">,</span> <span class="re0">$j</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="re0">$i</span><span class="sy0">--</span> <span class="sy0">&gt;</span> <span class="nu0">1</span> <span class="sy0">+</span> <span class="re0">$prefixLength</span><span class="sy0">;</span> <span class="re0">$j</span><span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="re0">$lower</span> <span class="sy0">=</span> <span class="re0">$min</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span>
        <span class="re0">$upper</span> <span class="sy0">=</span> <span class="re0">$max</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp;
        <span class="co1">// correct bounds if not final range</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$j</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="sy0">++</span><span class="re0">$lower</span><span class="sy0">;</span>
            <span class="sy0">--</span><span class="re0">$upper</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="co1">// lower bound</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$lower</span> <span class="sy0">&lt;</span> <span class="nu0">10</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="re0">$char</span> <span class="sy0">=</span> <span class="re0">$lower</span> <span class="sy0">==</span> <span class="nu0">9</span> ? <span class="nu0">9</span> <span class="sy0">:</span> <span class="st_h">'['</span> <span class="sy0">.</span> <span class="re0">$lower</span> <span class="sy0">.</span> <span class="st_h">'-9]'</span><span class="sy0">;</span>
            <span class="re0">$pattern</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span>
                <span class="br0">&#40;</span><span class="re0">$j</span> <span class="sy0">&gt;=</span> <span class="re0">$lenMin</span> ? <span class="st_h">''</span> <span class="sy0">:</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re0">$min</span><span class="sy0">,</span> <span class="re0">$lenDiff</span><span class="sy0">,</span> <span class="re0">$i</span> <span class="sy0">-</span> <span class="re0">$lenDiff</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
                <span class="sy0">.</span> <span class="re0">$char</span> <span class="sy0">.</span> <span class="kw3">str_repeat</span><span class="br0">&#40;</span><span class="re0">$digit</span><span class="sy0">,</span> <span class="re0">$j</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="co1">// upper bound</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$upper</span> <span class="sy0">&gt;=</span> <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="re0">$char</span> <span class="sy0">=</span> <span class="re0">$upper</span> ? <span class="st_h">'[0-'</span> <span class="sy0">.</span> <span class="re0">$upper</span> <span class="sy0">.</span> <span class="st_h">']'</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span>
            <span class="re0">$pattern</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re0">$max</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re0">$i</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="re0">$char</span> <span class="sy0">.</span> <span class="kw3">str_repeat</span><span class="br0">&#40;</span><span class="re0">$digit</span><span class="sy0">,</span> <span class="re0">$j</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// add middle range</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$j</span> <span class="sy0">||</span> <span class="re0">$max</span><span class="br0">&#91;</span><span class="re0">$prefixLength</span><span class="br0">&#93;</span> <span class="sy0">-</span> <span class="re0">$min</span><span class="br0">&#91;</span><span class="re0">$prefixLength</span><span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="re0">$prefix</span> <span class="sy0">=</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re0">$min</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re0">$prefixLength</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="re0">$lower</span> <span class="sy0">=</span> <span class="re0">$min</span><span class="br0">&#91;</span><span class="re0">$prefixLength</span><span class="br0">&#93;</span><span class="sy0">;</span>
        <span class="re0">$upper</span> <span class="sy0">=</span> <span class="re0">$max</span><span class="br0">&#91;</span><span class="re0">$prefixLength</span><span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp;
        <span class="co1">// correct bounds if not final range</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$j</span> <span class="sy0">&amp;&amp;</span> <span class="re0">$i</span> <span class="sy0">==</span> <span class="re0">$prefixLength</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="sy0">++</span><span class="re0">$lower</span><span class="sy0">;</span>
            <span class="sy0">--</span><span class="re0">$upper</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="re0">$char</span> <span class="sy0">=</span> <span class="re0">$lower</span> <span class="sy0">==</span> <span class="re0">$upper</span> ? <span class="re0">$lower</span> <span class="sy0">:</span> <span class="st_h">'['</span> <span class="sy0">.</span> <span class="re0">$lower</span> <span class="sy0">.</span> <span class="st_h">'-'</span> <span class="sy0">.</span> <span class="re0">$upper</span> <span class="sy0">.</span> <span class="st_h">']'</span><span class="sy0">;</span>
        <span class="re0">$pattern</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$prefix</span> <span class="sy0">.</span> <span class="re0">$char</span> <span class="sy0">.</span> <span class="kw3">str_repeat</span><span class="br0">&#40;</span><span class="re0">$digit</span><span class="sy0">,</span> <span class="re0">$lenMax</span> <span class="sy0">-</span> <span class="re0">$prefixLength</span> <span class="sy0">-</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw1">return</span> <span class="kw3">join</span><span class="br0">&#40;</span><span class="st_h">'|'</span><span class="sy0">,</span> <span class="re0">$pattern</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>

<p>My solution ended up along the same lines as Justin's, and although I had achieved my original aim of understanding his solution better, the real educational experience here was the inadequacy of my initial tests. I think I've now thoroughly learnt the lesson of testing with a comprehensive range of input.</p>
<p>Bearing in mind that this is just one function with a relatively small domain of useful input: If you <a href="http://en.wikipedia.org/wiki/Fuzz_testing">fuzzed</a> your own applications, what obscure bugs might you find?</p>
<p>As an aside, when I came back to this recently having decided to write an article on the topic, I found an <a href="http://code.activestate.com/recipes/534137/">elegant solution</a>, written in Python (of course), which uses the rather different approach of first partitioning the ranges with a recursive function and then constructing a regular expression for each one.</p>
<p>Out of curiosity I ported this to PHP too, but as you might expect it became decidedly less elegant and the depth of recursion segfaulted PHP on all but the most trivial input.</p>
<p class="credits">
    <a href="http://www.sxc.hu/photo/996475">Photo</a> by Jag arts.</p>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2009/03/numeric-ranges-in-regex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Playing golf with PHP</title>
		<link>http://arpad.co.uk/2008/09/playing-golf-with-php/</link>
		<comments>http://arpad.co.uk/2008/09/playing-golf-with-php/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 16:25:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://arpad.rajeczy.com/2008/09/playing-golf-with-php/</guid>
		<description><![CDATA[<a href="http://arpad.co.uk/2008/09/playing-golf-with-php/" title="Playing golf with PHP"><img src="http://arpad.co.uk/wp-content/uploads/yapb_cache/golfer_new.bfsh5wa7abwockkcc0sw8oscg.a9sxxja1njksswcs400wcc4cg.th.jpeg" width="180" height="126" alt="Playing golf with PHP" style="float:left;padding:0 10px 10px 0;" ></a>One of my geekiest hobbies is playing golf. Not the 18 holes of weathered drudgery kind, but the 18 hours of staring at the same 2 lines of code kind. If you still don't know what I'm talking about, the aim of the game is solve a given problem in the smallest amount of code [...]]]></description>
			<content:encoded><![CDATA[<a href="http://arpad.co.uk/2008/09/playing-golf-with-php/" title="Playing golf with PHP"><img src="http://arpad.co.uk/wp-content/uploads/yapb_cache/golfer_new.bfsh5wa7abwockkcc0sw8oscg.a9sxxja1njksswcs400wcc4cg.th.jpeg" width="180" height="126" alt="Playing golf with PHP" style="float:left;padding:0 10px 10px 0;" ></a><p>One of my geekiest hobbies is playing golf. Not the 18 holes of weathered drudgery kind, but the 18 hours of staring at the same 2 lines of code kind. If you still don't know what I'm talking about, the aim of the game is solve a given problem in the smallest amount of code (fewest strokes... geddit?).<span id="more-81"></span></p>
<p>Code golf has been played with various languages since at least the '50s, according to the famous <a href="http://terje2.frox25.no-ip.org/~golf-info/Book.html" target="_blank">Perlgolf History</a> book, but it was certainly the Perl golfers who took it to the next level. One might say Perl is perfectly suited for golf because of its perversely rich and succinct syntax, but I think golf's popularity in the Perl world says more about the mentality of the people who inhabit it. I can't imagine many VB.NET coders getting into it, even if their language wasn't so verbose.</p>
<p>Two years ago, <a href="http://www.29degrees.co.uk/" target="_blank">29 degrees</a> launched a brand new golfing website, <a href="http://www.codegolf.com/" target="_blank">codegolf.com</a>. The slick interface was a major attraction, no fiddling with test files required, just submit your code and see if it works. However, codegolf.com's biggest feature is that Perl, PHP, Ruby and Python can all compete on the same challenges together. While your PHP entries are unlikely to be troubling the top Perl entries, there's a fairly good chance of embarrassing some Ruby and Python coders <img src='http://arpad.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Since the PHP world is pretty new to all this, I've assembled some tips and tricks you can use to shorten your PHP solutions according to the codegolf.com rules. Hopefully needless to say, these should never get near any kind of production code.</p>
<ul>
<li>
<h3><a>Get a working version first</a></h3>
<p>This might seem like stating the obvious, but it's easy to miss a subtle error in a test case and then waste time golfing you code you have to throw away.</p>
</li>
<li>
<h3><a>Notices? What notices?</a></h3>
<p>Notices will be ignored, so you can skip setting variables to 0, null, "" or array() at the beginning of the script. This also means you can drop the quotes from some strings.</p>
</li>
<li>
<h3><a>The function with the shortest name may not be the shortest</a></h3>
<p>Don't always fixate on the functions with the shortest names, quite often a function with a longer name will save work elsewhere.</p>
</li>
<li>
<h3><a>Lookup tables</a></h3>
<p>You can often cut out a large part of code by looking the result up from a string rather than calculating it. Consider using pack() to squeeze more data into the same string. Aim to produce an alphanumeric string, so you can drop the quotes.</p>
</li>
<li>
<h3><a>Looping</a></h3>
<p><em>Foreach</em> loops are rarely the shortest. <em>While</em> and <em>for</em> loops are the same length, but <em>for</em> gives you two free semi-colons so it usually wins. Always try keep loops to one statement, so you can drop the braces.</p>
</li>
<li>
<h3><a>There's always another algorithm</a></h3>
<p>If you've spent ages on one approach and are still 50 bytes behind the guy ahead, it's probably time to think of a new algorithm.</p>
</li>
<li>
<h3><a>Bitwise tricks</a></h3>
<p>Bitwise OR with 0 is a nice alternative to <em>floor()</em>, so floor($a / $b) becomes $a / $b | 0. Changing the case of a letter in a string is another good one - $c &amp; "\xDF" is the same is strtoupper($c), and  $c | " " is the same as strtolower($c).</p>
</li>
<li>
<h3><a>Use literal characters instead of escapes</a></h3>
<p>While golfing it's easiest to keep characters escaped, but once you're ready to submit you can often save an extra few bytes by replacing escapes such as \n with a literal newline.</p>
</li>
</ul>
<p>Beware, code golf is highly addictive and can lead to broken keyboards, windows and families.</p>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/playing-golf-with-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Splitting a string into quoted and unquoted sections</title>
		<link>http://arpad.co.uk/2008/09/splitting-a-string-into-quoted-and-unquoted-sections/</link>
		<comments>http://arpad.co.uk/2008/09/splitting-a-string-into-quoted-and-unquoted-sections/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 03:32:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Regex]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[quote]]></category>

		<category><![CDATA[split]]></category>

		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=76</guid>
		<description><![CDATA[
&#60;?php
$str = 'unquoted section &#34;quoted&#34; and unquoted
    &#34;another quoted \&#34;with a subquote\&#34; section&#34; more unquoted';
preg_match_all&#40;'/&#34;(?:\\\\.&#124;[^&#34;])*&#34;&#124;[^&#34;]+/', $str, $m&#41;;
print_r&#40;$m&#41;;
?&#62;

Output

Array
(
    [0] => Array
        (
            [0] => unquoted section
       [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="re0">$str</span> <span class="sy0">=</span> <span class="st_h">'unquoted section &quot;quoted&quot; and unquoted
    &quot;another quoted \&quot;with a subquote\&quot; section&quot; more unquoted'</span><span class="sy0">;</span>
<span class="kw3">preg_match_all</span><span class="br0">&#40;</span><span class="st_h">'/&quot;(?:\\\\.|[^&quot;])*&quot;|[^&quot;]+/'</span><span class="sy0">,</span> <span class="re0">$str</span><span class="sy0">,</span> <span class="re0">$m</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw3">print_r</span><span class="br0">&#40;</span><span class="re0">$m</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Output</h4>
<pre>
Array
(
    [0] => Array
        (
            [0] => unquoted section
            [1] => "quoted"
            [2] =>  and unquoted
            [3] => "another quoted \"with a subquote\" section"
            [4] =>  more unquoted
        )

)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/splitting-a-string-into-quoted-and-unquoted-sections/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Function to readable</title>
		<link>http://arpad.co.uk/2008/09/function-to-readable/</link>
		<comments>http://arpad.co.uk/2008/09/function-to-readable/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 02:52:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[bitwise]]></category>

		<category><![CDATA[function]]></category>

		<category><![CDATA[human]]></category>

		<category><![CDATA[readable]]></category>

		<category><![CDATA[Regex]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=74</guid>
		<description><![CDATA[
&#60;?php
$str = 'Some_fugly_FunctionNaming_schemeHere';
$str = preg_replace&#40;'/(?&#60;=[a-z\d])([A-Z])&#124;_([a-zA-Z])/e', '&#34; \xDF&#34;&#38;&#34; $1$2&#34;', $str&#41;;
echo $str;
?&#62;

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="re0">$str</span> <span class="sy0">=</span> <span class="st_h">'Some_fugly_FunctionNaming_schemeHere'</span><span class="sy0">;</span>
<span class="re0">$str</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st_h">'/(?&lt;=[a-z\d])([A-Z])|_([a-zA-Z])/e'</span><span class="sy0">,</span> <span class="st_h">'&quot; \xDF&quot;&amp;&quot; $1$2&quot;'</span><span class="sy0">,</span> <span class="re0">$str</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw3">echo</span> <span class="re0">$str</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/function-to-readable/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Linear to nested array</title>
		<link>http://arpad.co.uk/2008/09/linear-to-nested-array/</link>
		<comments>http://arpad.co.uk/2008/09/linear-to-nested-array/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 02:46:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[array]]></category>

		<category><![CDATA[multi-dimensional]]></category>

		<category><![CDATA[nested]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=71</guid>
		<description><![CDATA[
&#60;?php
$a = array&#40;'a', 'b', 'c'&#41;;
foreach &#40;array_reverse&#40;$a&#41; as $v&#41; &#123;
    $b = isset&#40;$b&#41; ? array&#40;$v =&#62; $b&#41; : array&#40;$v&#41;;
&#125;
print_r&#40;$b&#41;;
?&#62;

Output

Array
(
    [a] => Array
        (
            [b] => Array
       [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="re0">$a</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'a'</span><span class="sy0">,</span> <span class="st_h">'b'</span><span class="sy0">,</span> <span class="st_h">'c'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="kw3">array_reverse</span><span class="br0">&#40;</span><span class="re0">$a</span><span class="br0">&#41;</span> <span class="kw1">as</span> <span class="re0">$v</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$b</span> <span class="sy0">=</span> <span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$b</span><span class="br0">&#41;</span> ? <span class="kw3">array</span><span class="br0">&#40;</span><span class="re0">$v</span> <span class="sy0">=&gt;</span> <span class="re0">$b</span><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="re0">$v</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw3">print_r</span><span class="br0">&#40;</span><span class="re0">$b</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Output</h4>
<pre>
Array
(
    [a] => Array
        (
            [b] => Array
                (
                    [0] => c
                )

        )

)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/linear-to-nested-array/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Removing duplicate characters</title>
		<link>http://arpad.co.uk/2008/09/removing-duplicate-characters/</link>
		<comments>http://arpad.co.uk/2008/09/removing-duplicate-characters/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 02:43:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Regex]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[character]]></category>

		<category><![CDATA[duplicate]]></category>

		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=69</guid>
		<description><![CDATA[
&#60;?php
$str = 'foobarrrr';
$str = preg_replace&#40;'/(.)\1+/s', '$1', $str&#41;;
echo $str; // fobar
?&#62;

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="re0">$str</span> <span class="sy0">=</span> <span class="st_h">'foobarrrr'</span><span class="sy0">;</span>
<span class="re0">$str</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st_h">'/(.)\1+/s'</span><span class="sy0">,</span> <span class="st_h">'$1'</span><span class="sy0">,</span> <span class="re0">$str</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw3">echo</span> <span class="re0">$str</span><span class="sy0">;</span> <span class="co1">// fobar</span>
<span class="sy1">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/removing-duplicate-characters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The adventure of PHP and the magic quotes</title>
		<link>http://arpad.co.uk/2008/09/the-adventure-of-php-and-the-magic-quotes/</link>
		<comments>http://arpad.co.uk/2008/09/the-adventure-of-php-and-the-magic-quotes/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 18:38:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=30</guid>
		<description><![CDATA[Back in PHP 2, the "magic quotes" setting seemed like a great idea. It would automatically escape all of your input so you didn't have to worry about those pesky SQL injections. Any dodgy characters entered by the user would be automatically escaped by a backslash.

Like <em>register_globals</em>, it helped lower the barrier of entry to building a dynamic website by removing some of the complexity. However it certainly wasn't without sacrifice, problems with the implementation quickly appeared and continued to abound for the next ten years. Finally in PHP 5.2.2 we got an implementation which (as far as its intentions went) seemed to be bug free, but of course by then it was turned off by default and was already slated to be dropped in PHP 6.]]></description>
			<content:encoded><![CDATA[<p>Back in PHP 2, the "magic quotes" setting seemed like a great idea. It would automatically escape all of your input so you didn't have to worry about those pesky SQL injections. Any dodgy characters entered by the user would be automatically escaped by a backslash.</p>
<p>Like <em>register_globals</em>, it helped lower the barrier of entry to building a dynamic website by removing some of the complexity. However it certainly wasn't without sacrifice, problems with the implementation quickly appeared and continued to abound for the next ten years. Finally in PHP 5.2.2 we got an implementation which (as far as its intentions went) seemed to be bug free, but of course by then it was turned off by default and was already slated to be dropped in PHP 6.</p>
<h3><a>Why are magic quotes so bad?</a></h3>
<ul>
<li>
<h4>Insufficiency</h4>
<p>
This is the single biggest problem with magic quotes. Even if you follow all the instructions right and code defensively, relying on magic quotes to escape strings for database queries is still not secure. Magic quotes uses <em>addslashes()</em> for its escaping which doesn't care about the character encoding of your database, meaning it's vulnerable to multi-byte character attacks as <a title="addslashes() Versus mysql_real_escape_string()" href="http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-real-escape-string" target="_blank">explained by Chris Shiflett</a>.</p>
</li>
<li>
<h4>Portability</h4>
<p>
You simply cannot rely on magic quotes being on or off if you expect to distribute your PHP script to others, since many hosts don't provide a way of changing the setting.</p>
</li>
<li>
<h4>Complacency<br />
</h4>
<p>The very concept of magic quotes fosters complacency. Why bother validating input if it's going to be escaped anyway? All too often on IRC I see code which completely neglects validation - strings and supposedly numeric values going straight into the query with no effort being made to check them. Examples can be found in countless books and tutorials, and they are still being written.</p>
</li>
<li>
<h4>Inconsistency<br />
</h4>
<p>Depending on which version of PHP you use, you can expect vastly different results from magic quotes. As mentioned above, PHP 5.2.2 was the first version in which magic quotes actually did what it said on the tin. Some features which may or may not work include: escaping double quotes; escaping the <em>$_SERVER</em> and <em>$_ENV</em> arrays; escaping the keys of arrays.</p>
</li>
<li>
<h4>Performance<br />
</h4>
<p>When magic quotes is on, <em>everything</em> is escaped. You might have a page which only uses PHP to output the current date, but if the user decides to send 8 MB of post data, it's going to be escaped whether you like it or not, before your script even starts. Extreme examples aside, any posted value which you wouldn't need to escape is another useless call to <em>addslashes()</em>.</p>
</li>
<li>
<h4>Inconvenience<br />
</h4>
<p>As convenient as it is not worrying about having to escape anything, once you're aware of magic quotes' flaws, they become a real pain in the arse. We've all seen sites suffering from double escaping, where content ends up being actually output like "the Pope's underpants".</p>
</li>
</ul>
<h3><a>Coping with magic quotes</a></h3>
<p>The number one piece of advice regarding magic quotes has to be, <strong>turn them off!</strong> However that's easier said than done. Since it takes effect before the script is run you can't just use <en>ini_set()</em> at the top of your script.</p>
<p>The luckiest people host their own sites or have a host agreeable enough to turn it off in <em>php.ini</em> or the web server configuration. The slightly less lucky people can still control PHP settings per-directory, for example by the use of an <em>.htaccess</em> file.</p>
<p>Everyone else is forced to try to cope with it at runtime, and this is where the real fun begins. Since PHP 4, there's been the handy <em>get_magic_quotes_gpc()</em> function, which is most commonly seen used like the following example from the PHP manual:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">get_magic_quotes_gpc</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$lastname</span> <span class="sy0">=</span> <span class="kw3">addslashes</span><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st_h">'lastname'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
    <span class="re0">$lastname</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st_h">'lastname'</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>

<p>Unfortunately, <em>get_magic_quotes_gpc()</em> is not aware of the <em>magic_quotes_sybase</em> setting, which changes the escape method to Sybase-style doubled quotes, and also knows nothing of the various inconsistencies of magic quotes. Therefore you could easily be applying <en>addslashes()</em> where you don't need to and vice-versa.</p>
<p>The other common approach is to try to completely undo the effects of magic quotes, in the hope that it will end up as if magic quotes was never turned on, and then proceed with proper escaping. This solution means that at worst you'll be double escaping - there's no chance of anything dodgy getting through as long as your proper escaping is effective. However, it has some problems of its own.</p>
<p>At the primitive end of things, you might see code like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">get_magic_quotes_gpc</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$_GET</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes'</span><span class="sy0">,</span> <span class="re0">$_GET</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$_POST</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes'</span><span class="sy0">,</span> <span class="re0">$_POST</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$_COOKIE</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes'</span><span class="sy0">,</span> <span class="re0">$_COOKIE</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$_REQUEST</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes'</span><span class="sy0">,</span> <span class="re0">$_REQUEST</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>

<p>Ignoring the potential double-escaping, this solution has two fundamental problems. Firstly any arrays in the input will be converted to the string "Array", which is slightly less useful. Secondly it only fixes the values, ignoring the keys.</p>
<p>It is quite simple to make a recursive function to tackle the first problem, and that's what the PHP manual opts for on its page on <a href="http://www.php.net/manual/en/security.magicquotes.disabling.php">Disabling Magic Quotes</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">get_magic_quotes_gpc</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">function</span> stripslashes_deep<span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="re0">$value</span> <span class="sy0">=</span> <span class="kw3">is_array</span><span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span> ?
                    <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes_deep'</span><span class="sy0">,</span> <span class="re0">$value</span><span class="br0">&#41;</span> <span class="sy0">:</span>
                    <span class="kw3">stripslashes</span><span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
        <span class="kw1">return</span> <span class="re0">$value</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="re0">$_POST</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes_deep'</span><span class="sy0">,</span> <span class="re0">$_POST</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$_GET</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes_deep'</span><span class="sy0">,</span> <span class="re0">$_GET</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$_COOKIE</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes_deep'</span><span class="sy0">,</span> <span class="re0">$_COOKIE</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$_REQUEST</span> <span class="sy0">=</span> <span class="kw3">array_map</span><span class="br0">&#40;</span><span class="st_h">'stripslashes_deep'</span><span class="sy0">,</span> <span class="re0">$_REQUEST</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>

<p>The recursion means that it won't destroy your arrays but it still suffers from the second problem, not escaping the keys, and it introduces yet another problem - arbitrary recursion depth. Consider the following query string:</p>
<pre>
foo[][][][][][][][][][]=1&#038;foo[][][][][][][][][][1]=2
</pre>
<p>Fixing those two values alone takes 22 function calls, imagine how much work a single request could cause using the maximum post data size - by default 8 MB. That's a pretty effective basis for a DoS attack.</p>
<p>In practice PHP will fall over far before it completes all that work, namely because it sucks at recursion. A new configuration setting (<em>max_input_nesting_level</em>) was added in 5.2.3 to control the maximum recursion depth, but hosts providing 5.2.3 or above are sadly in the minority.</p>
<p>The easy solution is to add another argument and a depth check to that function, but that leaves the problem of escaping the keys, and the double-escaping problem we've been ignoring from the beginning.</p>
<p>Enter, <a href="http://pear.php.net/package/PHP_Compat">PHP_Compat</a>. Aidan Lister pioneered this awesome <a href="http://pear.php.net/">PEAR</a> package and I've proudly been helping out for the last couple of years.</p>
<p>In our upcoming release, PHP_Compat 1.6.0, we've added an environment module which includes magic_quotes_gpc among the settings it fully supports changing at runtime. Because of the nature of the package we've gone with the second approach, trying to restore the environment to exactly how it was before magic_quotes_gpc took effect. However we use an iterative algorithm so recursion depth isn't a problem and we take into account every inconsistency going back to PHP 4.0, so you shouldn't experience any double-escaping at all.</p>
<h3><a>The future</a></h3>
<p>Until they're gone for good, we have to spread the message that <strong>magic quotes are evil, turn them off!</strong> The less people make use of magic quotes, the sooner we can be rid of them. PHP 6 is continually being delayed and at the rate people have moved to PHP 5 it will take at least another ten years for everyone to be on PHP 6. I'm sure we'll see plenty more adventures along the way.</p>
<p class="update">
<h3><a>Update:</a></h3>
<p>For completeness I think I should point out here, that yet another problem with magic_quotes_gpc emerged with PHP 5.2.7, it was <a href="http://www.php.net/index.php#id2008-12-07-1">completely broken</a>.</p>
<p>Also Chris Shiflett added in a kind comment on <a href="http://www.phpdeveloper.org/news/11589">phpdeveloper.org</a>:</p>
<blockquote><p>
One thing I would add to your list is the fact that magic quotes is an escaping solution. Escaping input provides a unique set of challenges, because it's an inappropriate design decision. Because data is not necessarily destined for exactly one context, it is only important to be sure input is valid. (Filter input.) Each context can then be handled as needed, typically when the data leaves PHP for another context. (Escape output.)</p>
<p>Magic quotes violates this simple tenet, and in my opinion, this is the root cause of most of the problems related to using it.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/the-adventure-of-php-and-the-magic-quotes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Random string</title>
		<link>http://arpad.co.uk/2008/09/random-string/</link>
		<comments>http://arpad.co.uk/2008/09/random-string/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 17:31:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Regex]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[character]]></category>

		<category><![CDATA[random]]></category>

		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=21</guid>
		<description><![CDATA[
&#60;?php
&#160;
/**
 * Generates a random string.
 *
 * @param    int    $length
 *   The length of the string
 * @param    string $ranges
 *   The characters to use, formatted like a regex character class (a-fA-F0-9)
 * @param    bool   $unique
 [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="co4">/**
 * Generates a random string.
 *
 * @param    int    $length
 *   The length of the string
 * @param    string $ranges
 *   The characters to use, formatted like a regex character class (a-fA-F0-9)
 * @param    bool   $unique
 *   Every character in the result is unique or not
 * @return   string
 *   The resulting string.
 */</span>
<span class="kw1">require_once</span><span class="br0">&#40;</span><span class="st_h">'preg_expand.php'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw2">function</span> random_string<span class="br0">&#40;</span><span class="re0">$length</span> <span class="sy0">=</span> <span class="nu0">6</span><span class="sy0">,</span> <span class="re0">$ranges</span> <span class="sy0">=</span> <span class="st_h">'a-zA-Z0-9'</span><span class="sy0">,</span> <span class="re0">$unique</span> <span class="sy0">=</span> <span class="kw2">false</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$out</span> <span class="sy0">=</span> <span class="st_h">''</span><span class="sy0">;</span>
    <span class="re0">$chars</span> <span class="sy0">=</span> preg_expand<span class="br0">&#40;</span><span class="re0">$ranges</span><span class="sy0">,</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$unique</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="re0">$keys</span> <span class="sy0">=</span> <span class="kw3">array_rand</span><span class="br0">&#40;</span><span class="re0">$chars</span><span class="sy0">,</span> <span class="re0">$length</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
        <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">=</span> <span class="re0">$length</span><span class="sy0">;</span> <span class="re0">$i</span><span class="sy0">--;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="re0">$keys</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw3">array_rand</span><span class="br0">&#40;</span><span class="re0">$chars</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$keys</span> <span class="kw1">as</span> <span class="re0">$k</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="re0">$out</span> <span class="sy0">.=</span> <span class="re0">$chars</span><span class="br0">&#91;</span><span class="re0">$k</span><span class="br0">&#93;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">return</span> <span class="re0">$out</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="co4">/**
 * Quick and simple version
 */</span>
<span class="kw2">function</span> random_string_simple<span class="br0">&#40;</span><span class="re0">$length</span> <span class="sy0">=</span> <span class="nu0">6</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$chars</span> <span class="sy0">=</span> <span class="st_h">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'</span><span class="sy0">;</span>
    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">=</span> <span class="re0">$length</span><span class="sy0">,</span> <span class="re0">$out</span> <span class="sy0">=</span> <span class="st_h">''</span><span class="sy0">;</span> <span class="re0">$i</span><span class="sy0">--;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="re0">$out</span> <span class="sy0">.=</span> <span class="re0">$chars</span><span class="br0">&#123;</span><span class="kw3">rand</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">61</span><span class="br0">&#41;</span><span class="br0">&#125;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">return</span> <span class="re0">$out</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Example</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'&lt;h4&gt;Default:&lt;/h4&gt;'</span><span class="sy0">,</span> random_string<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="st_h">'&lt;br /&gt;&lt;br /&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'&lt;h4&gt;8 characters, A-F0-9:&lt;/h4&gt;'</span><span class="sy0">,</span> random_string<span class="br0">&#40;</span><span class="nu0">8</span><span class="sy0">,</span> <span class="st_h">'A-F0-9'</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="st_h">'&lt;br /&gt;&lt;br /&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'&lt;h4&gt;6 characters, a-z, unique:&lt;/h4&gt;'</span><span class="sy0">,</span> random_string<span class="br0">&#40;</span><span class="nu0">6</span><span class="sy0">,</span> <span class="st_h">'a-z'</span><span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="st_h">'&lt;br /&gt;&lt;br /&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'&lt;h4&gt;Simple:&lt;/h4&gt;'</span><span class="sy0">,</span> random_string_simple<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Output</h4>
<pre>
<h4>Default:</h4>

shAjlw
<h4>8 characters, A-F0-9:</h4>

9A181CE7
<h4>6 characters, a-z, unique:</h4>

fgkqsw
<h4>Simple:</h4>

RsxWZj
</pre>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/random-string/feed/</wfw:commentRss>
		</item>
		<item>
		<title>preg_expand</title>
		<link>http://arpad.co.uk/2008/09/preg_expand/</link>
		<comments>http://arpad.co.uk/2008/09/preg_expand/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 17:27:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Regex]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[character]]></category>

		<category><![CDATA[range]]></category>

		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=6</guid>
		<description><![CDATA[
&#60;?php
&#160;
/**
 * Expands all characters from the given PCRE character class definition. 
 *
 * @param    string    $in
 *   The input character class (not contained in '[]')
 * @param    bool      $string
 *   Set to true to return [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="co4">/**
 * Expands all characters from the given PCRE character class definition. 
 *
 * @param    string    $in
 *   The input character class (not contained in '[]')
 * @param    bool      $string
 *   Set to true to return the result as a string
 * @param    int       $begin
 *   The start of the character range to consider
 * @param    int       $end
 *   The end of the character range to consider
 * @return   mixed
 *   All the characters specified by the input. This is a string if the $string
 *   argument has been provided, or else an array with one element per character.
 */</span>
<span class="kw2">function</span> preg_expand<span class="br0">&#40;</span><span class="re0">$in</span><span class="sy0">,</span> <span class="re0">$string</span> <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">,</span> <span class="re0">$begin</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re0">$end</span> <span class="sy0">=</span> <span class="nu0">127</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">is_string</span><span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#41;</span> <span class="sy0">||</span> <span class="sy0">!</span><span class="br0">&#40;</span><span class="re0">$len</span> <span class="sy0">=</span> <span class="kw3">strlen</span><span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="re0">$range</span> <span class="sy0">=</span> <span class="kw3">range</span><span class="br0">&#40;</span><span class="kw3">chr</span><span class="br0">&#40;</span><span class="re0">$begin</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw3">chr</span><span class="br0">&#40;</span><span class="re0">$end</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$in</span> <span class="sy0">=</span> <span class="kw3">strtr</span><span class="br0">&#40;</span><span class="re0">$in</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'['</span> <span class="sy0">=&gt;</span> <span class="st_h">'\['</span><span class="sy0">,</span> <span class="st_h">']'</span> <span class="sy0">=&gt;</span> <span class="st_h">'\]'</span><span class="sy0">,</span> <span class="st_h">'/'</span> <span class="sy0">=&gt;</span> <span class="st_h">'\/'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$in</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#123;</span><span class="nu0">0</span><span class="br0">&#125;</span> <span class="sy0">==</span> <span class="st_h">'^'</span> ? <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re0">$in</span><span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="st_h">'^'</span> <span class="sy0">.</span> <span class="re0">$in</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$in</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st_h">'/['</span> <span class="sy0">.</span><span class="re0">$in</span> <span class="sy0">.</span> <span class="st_h">']/'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="sy0">,</span> <span class="kw3">implode</span><span class="br0">&#40;</span><span class="re0">$range</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">return</span> <span class="re0">$string</span> ? <span class="re0">$in</span> <span class="sy0">:</span> str_split<span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Example:</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'Alphabet: '</span><span class="sy0">,</span> preg_expand<span class="br0">&#40;</span><span class="st_h">'a-z'</span><span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="st_h">'&lt;br /&gt;&lt;br /&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'Hexadecimal: '</span><span class="sy0">,</span> preg_expand<span class="br0">&#40;</span><span class="st_h">'A-F\d'</span><span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="st_h">'&lt;br /&gt;&lt;br /&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Output:</h4>
<pre>
Alphabet: abcdefghijklmnopqrstuvwxyz

Hexadecimal: 0123456789ABCDEF</pre>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/preg_expand/feed/</wfw:commentRss>
		</item>
		<item>
		<title>secondsh</title>
		<link>http://arpad.co.uk/2008/09/secondshfoobar/</link>
		<comments>http://arpad.co.uk/2008/09/secondshfoobar/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 17:27:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[human]]></category>

		<category><![CDATA[readable]]></category>

		<category><![CDATA[seconds]]></category>

		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://rajeczy.com/arpad/wordpress/?p=9</guid>
		<description><![CDATA[
&#60;?php
/**
 * Turns a number of seconds into a human readable time.
 * This function is NOT calendar aware, months and years are based on the
 * average days per year in the Gregorian calendar.
 *
 * @param  int    $in
 *   the input number of seconds
 * @return string
 [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="co4">/**
 * Turns a number of seconds into a human readable time.
 * This function is NOT calendar aware, months and years are based on the
 * average days per year in the Gregorian calendar.
 *
 * @param  int    $in
 *   the input number of seconds
 * @return string
 *   a string representation of the input, broken down into larger units
 */</span>
<span class="kw2">function</span> secondsh<span class="br0">&#40;</span><span class="re0">$in</span><span class="sy0">,</span> <span class="re0">$limit</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re0">$sep</span> <span class="sy0">=</span> <span class="st_h">', '</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    <span class="re0">$units</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'second'</span><span class="sy0">,</span> <span class="st_h">'minute'</span><span class="sy0">,</span> <span class="st_h">'hour'</span><span class="sy0">,</span> <span class="st_h">'day'</span><span class="sy0">,</span> <span class="st_h">'week'</span><span class="sy0">,</span> <span class="st_h">'month'</span><span class="sy0">,</span> <span class="st_h">'year'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$factors</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="sy0">,</span> <span class="nu0">60</span><span class="sy0">,</span> <span class="nu0">3600</span><span class="sy0">,</span> <span class="nu0">86400</span><span class="sy0">,</span> <span class="nu0">604800</span><span class="sy0">,</span> <span class="nu0">2629746</span><span class="sy0">,</span> <span class="nu0">31556952</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">=</span> <span class="nu0">7</span><span class="sy0">,</span> <span class="re0">$bal</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="re0">$i</span><span class="sy0">--;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="re0">$cur</span> <span class="sy0">=</span> <span class="kw3">floor</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$in</span> <span class="sy0">-</span> <span class="re0">$bal</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="re0">$factors</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$cur</span> <span class="sy0">&amp;&amp;</span> <span class="br0">&#40;</span><span class="re0">$i</span> <span class="sy0">||</span> <span class="re0">$in</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw1">continue</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
        <span class="re0">$bal</span> <span class="sy0">+=</span> <span class="re0">$cur</span> <span class="sy0">*</span> <span class="re0">$factors</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="sy0">;</span>
        <span class="re0">$ret</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$cur</span> <span class="sy0">.</span> <span class="st_h">' '</span> <span class="sy0">.</span> <span class="re0">$units</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span> <span class="sy0">.</span> <span class="br0">&#40;</span><span class="re0">$cur</span> <span class="sy0">!=</span> <span class="nu0">1</span> ? <span class="st_h">'s'</span> <span class="sy0">:</span> <span class="st_h">''</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$limit</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="re0">$ret</span> <span class="sy0">=</span> <span class="kw3">array_slice</span><span class="br0">&#40;</span><span class="re0">$ret</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re0">$limit</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">return</span> <span class="kw3">implode</span><span class="br0">&#40;</span><span class="re0">$sep</span><span class="sy0">,</span> <span class="re0">$ret</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Example</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="re0">$a</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">1</span><span class="sy0">,</span> <span class="nu0">30</span><span class="sy0">,</span> <span class="nu0">60</span><span class="sy0">,</span> <span class="nu0">3599</span><span class="sy0">,</span> <span class="nu0">3600</span><span class="sy0">,</span> <span class="nu0">100000</span><span class="sy0">,</span> <span class="nu0">2419200</span><span class="sy0">,</span> <span class="nu0">2500000</span><span class="sy0">,</span> <span class="nu0">555555555</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'&lt;strong&gt;Default&lt;/strong&gt;&lt;table&gt;'</span><span class="sy0">;</span>
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$a</span> <span class="kw1">as</span> <span class="re0">$v</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw3">echo</span> <span class="st_h">'&lt;tr&gt;&lt;td style=&quot;padding-right:20px&quot;&gt;'</span> <span class="sy0">.</span> <span class="re0">$v</span> <span class="sy0">.</span> <span class="st_h">'&lt;/td&gt;&lt;td&gt;'</span> <span class="sy0">.</span> secondsh<span class="br0">&#40;</span><span class="re0">$v</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st_h">'&lt;/td&gt;&lt;/tr&gt;'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw3">echo</span> <span class="st_h">'&lt;/table&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'&lt;br /&gt;&lt;br /&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">echo</span> <span class="st_h">'&lt;strong&gt;Limit 2&lt;/strong&gt;&lt;table&gt;'</span><span class="sy0">;</span>
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$a</span> <span class="kw1">as</span> <span class="re0">$v</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw3">echo</span> <span class="st_h">'&lt;tr&gt;&lt;td style=&quot;padding-right:20px&quot;&gt;'</span> <span class="sy0">.</span> <span class="re0">$v</span> <span class="sy0">.</span> <span class="st_h">'&lt;/td&gt;&lt;td&gt;'</span> <span class="sy0">.</span> secondsh<span class="br0">&#40;</span><span class="re0">$v</span><span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st_h">'&lt;/td&gt;&lt;/tr&gt;'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw3">echo</span> <span class="st_h">'&lt;/table&gt;'</span><span class="sy0">;</span>
&nbsp;
<span class="sy1">?&gt;</span></pre></div></div>

<h4>Output</h4>
<pre>
<strong>Default</strong>
<table>
<tbody>
<tr>
<td style="padding-right: 20px;">0</td>
<td>0 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">1</td>
<td>1 second</td>
</tr>
<tr>
<td style="padding-right: 20px;">30</td>
<td>30 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">60</td>
<td>1 minute</td>
</tr>
<tr>
<td style="padding-right: 20px;">3599</td>
<td>59 minutes, 59 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">3600</td>
<td>1 hour</td>
</tr>
<tr>
<td style="padding-right: 20px;">100000</td>
<td>1 day, 3 hours, 46 minutes, 40 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">2419200</td>
<td>4 weeks</td>
</tr>
<tr>
<td style="padding-right: 20px;">2500000</td>
<td>4 weeks, 22 hours, 26 minutes, 40 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">555555555</td>
<td>17 years, 7 months, 1 week, 20 hours, 39 minutes, 9 seconds</td>
</tr>
</tbody>
</table>

<strong>Limit 2</strong>
<table>
<tbody>
<tr>
<td style="padding-right: 20px;">0</td>
<td>0 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">1</td>
<td>1 second</td>
</tr>
<tr>
<td style="padding-right: 20px;">30</td>
<td>30 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">60</td>
<td>1 minute</td>
</tr>
<tr>
<td style="padding-right: 20px;">3599</td>
<td>59 minutes, 59 seconds</td>
</tr>
<tr>
<td style="padding-right: 20px;">3600</td>
<td>1 hour</td>
</tr>
<tr>
<td style="padding-right: 20px;">100000</td>
<td>1 day, 3 hours</td>
</tr>
<tr>
<td style="padding-right: 20px;">2419200</td>
<td>4 weeks</td>
</tr>
<tr>
<td style="padding-right: 20px;">2500000</td>
<td>4 weeks, 22 hours</td>
</tr>
<tr>
<td style="padding-right: 20px;">555555555</td>
<td>17 years, 7 months</td>
</tr>
</table>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://arpad.co.uk/2008/09/secondshfoobar/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
