<?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>Infinity-Infinity &#187; PHP</title>
	<atom:link href="http://infinity-infinity.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://infinity-infinity.com</link>
	<description>A blog and stuff.</description>
	<lastBuildDate>Sat, 31 Jul 2010 16:03:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>10 PHP functions you (probably) never use</title>
		<link>http://infinity-infinity.com/2009/07/10-php-functions-you-probably-never-use/</link>
		<comments>http://infinity-infinity.com/2009/07/10-php-functions-you-probably-never-use/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 15:52:58 +0000</pubDate>
		<dc:creator>Brendon</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://infinity-infinity.com/?p=132</guid>
		<description><![CDATA[When scripting in PHP, we often restrict ourselves to a limited number of API functions: the common ones, like print(), header(), define(), isset(), htmlspecialchars(), etc. If some needed functionality doesn&#8217;t exist, we often write it making use of these basic components which we have in mind. The PHP API actually offers a lot of functionality, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Finfinity-infinity.com%2F2009%2F07%2F10-php-functions-you-probably-never-use%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Finfinity-infinity.com%2F2009%2F07%2F10-php-functions-you-probably-never-use%2F" height="61" width="51" /></a></div><p>When scripting in PHP, we often restrict ourselves to a limited number of API functions: the <em>common</em> ones, like print(), header(), define(), isset(), htmlspecialchars(), etc. If some needed functionality doesn&#8217;t exist, we often write it making use of these basic components which we have in mind. The PHP API actually offers a lot of functionality, some useless and some useful; often seldom used. I have been looking through the available functions and was interested to find some really cool functions that I <em>should</em> have known about. Here, I share my findings.<span id="more-132"></span></p>
<span id="sys_getloadavg"><h3>1. sys_getloadavg()</h3></span>
<p><a href="http://uk.php.net/sys_getloadavg">sys_getloadvg()</a> is a function which returns three samples of the &#8220;load&#8221; on a system. Load is the number of processes in the system run queue. The 3 items in the array are the average load for the past 1, 5 and 15 minutes. The PHP Manual shows a great usage of this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$load</span> <span style="color: #339933;">=</span> sys_getloadavg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$load</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">80</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;">'HTTP/1.1 503 Too busy, try again later'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Server too busy. Please try again later.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Rather than have your web service become unavailable for everyone, you simply <em>die</em> when there&#8217;s too much load — primitively, this will allow some requests and deny others. The function will not work on Windows, though.</p>
<span id="pack"><h3>2. pack()</h3></span>
<p>I actually use <a href="http://uk.php.net/pack">pack()</a> fairly often, to make the 32-byte hexadecimal strings returned by <a href="http://uk.php.net/md5">md5()</a> into 16-byte binary strings*:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pass_hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pack</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;H*&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my-password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass_hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my-password&quot;</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: #666666; font-style: italic;">// equivalent (PHP 5+)</span></pre></div></div>

<p>It is very useful when storing data in databases; to save space. (In the case of packing hexadecimal values to binary strings).</p>
<span id="cal_days_in_month"><h3>3. cal_days_in_month()</h3></span>
<p><a href="http://uk.php.net/cal_days_in_month">cal_days_in_month()</a> usefully returns the number of days in a given month:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$days</span> <span style="color: #339933;">=</span> <span style="color: #990000;">cal_days_in_month</span><span style="color: #009900;">&#40;</span>CAL_GREGORIAN<span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 31</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$days</span> <span style="color: #339933;">-</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; days until &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1970</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<span id="4.__"><h3>4. _()</h3></span>
<p>If you&#8217;ve developed for WordPress, you&#8217;ll know about the __() and _e() functions to make the software i18n-able. You can use <a href="http://uk.php.net/manual/en/function.gettext.php">gettext()</a> (or _(), which is an alias), together with some other functions, to achieve the same functionality, in WordPress or not. This example was taken from the PHP Manual:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Set language to German</span>
<span style="color: #990000;">setlocale</span><span style="color: #009900;">&#40;</span>LC_ALL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'de_DE'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Specify location of translation tables</span>
<span style="color: #990000;">bindtextdomain</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myPHPApp&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;./locale&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Choose domain</span>
<span style="color: #990000;">textdomain</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myPHPApp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> _<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Have a nice day&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You will need to <a href="http://uk2.php.net/manual/en/gettext.installation.php">build</a> PHP with GNU gettext support. I suspect that there is a third-party solution out there which does the same thing, working on a standard installation. (Edit: in fact, there is &#8212; <a href="https://launchpad.net/php-gettext/">here</a>; thanks <a href="http://infinity-infinity.com/2009/07/10-php-functions-you-probably-never-use/#comment-915">Toni</a>).  </p>
<span id="get_browser"><h3>5. get_browser()</h3></span>
<p>Wouldn&#8217;t it be nice to find out what a user&#8217;s browser could do before sending the page? Well, you can with <a href="http://uk.php.net/get_browser">get_browser()</a>. You will need <a href="http://browsers.garykeith.com/downloads.asp">php_browscap.ini</a> first, and point the <a href="http://uk2.php.net/manual/en/misc.configuration.php#ini.browscap">browscap directive</a> to the file. You could have something similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_browser</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$browser</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;frames&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #000088;">$browser</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;cookies&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Please download an up-to-date browser. Some sections of this site may be inaccessible&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will not detect individual configurations of browsers, however; it can not be used to detect whether Javascript is enabled, for example. It may be useful to profile users — ie, by what browser and platform they use.</p>
<span id="debug_print_backtrace"><h3>6. debug_print_backtrace()</h3></span>
<p>It can be quite difficult to trace through code manually, particularly when looking for a logic error; after all, you wrote the logic! <a href="http://uk.php.net/debug_print_backtrace">debug_print_backtrace()</a> can get you out of a difficult situation. Here the function is being used to understand a rather pointless script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> iterate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span>
		recur<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> recur<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$a</span><span style="color: #339933;">++;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// how did I get here?</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	debug_print_backtrace<span style="color: #009900;">&#40;</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: #000088;">$a</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span>
		iterate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
iterate<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;"># OUTPUT:
</span>
<span style="color: #666666; font-style: italic;">#0  recur() called at [C:\htdocs\php_stuff\index.php:8]
</span><span style="color: #666666; font-style: italic;">#1  iterate() called at [C:\htdocs\php_stuff\index.php:25]
</span>
<span style="color: #666666; font-style: italic;">#0  recur() called at [C:\htdocs\php_stuff\index.php:8]
</span><span style="color: #666666; font-style: italic;">#1  iterate() called at [C:\htdocs\php_stuff\index.php:21]
</span><span style="color: #666666; font-style: italic;">#2  recur() called at [C:\htdocs\php_stuff\index.php:8]
</span><span style="color: #666666; font-style: italic;">#3  iterate() called at [C:\htdocs\php_stuff\index.php:25]
</span>
<span style="color: #666666; font-style: italic;">#0  recur() called at [C:\htdocs\php_stuff\index.php:8]
</span><span style="color: #666666; font-style: italic;">#1  iterate() called at [C:\htdocs\php_stuff\index.php:21]
</span><span style="color: #666666; font-style: italic;">#2  recur() called at [C:\htdocs\php_stuff\index.php:8]
</span><span style="color: #666666; font-style: italic;">#3  iterate() called at [C:\htdocs\php_stuff\index.php:21]
</span><span style="color: #666666; font-style: italic;">#4  recur() called at [C:\htdocs\php_stuff\index.php:8]
</span><span style="color: #666666; font-style: italic;">#5  iterate() called at [C:\htdocs\php_stuff\index.php:25]
</span>
<span style="color: #009900;">&#91;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#93;</span></pre></div></div>

<span id="metaphone"><h3>7. metaphone()</h3></span>
<p><a href="http://uk.php.net/metaphone">metaphone()</a> is a function returning the same <em>key</em> for words which sound the same. <a href="http://uk.php.net/soundex">soundex()</a> does the same thing, but is less accurate (according to PHP Manual):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">metaphone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;train&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TRN</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">metaphone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;terrain&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// TRN</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">metaphone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;not a train&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// NTTRN</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">soundex</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;train&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// T650</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">soundex</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;terrain&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// T650</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">soundex</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;not a train&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// N336</span></pre></div></div>

<span id="natsort"><h3>8. natsort()</h3></span>
<p><a href="http://uk.php.net/natsort">natsort()</a> is a function which will sort items in an array <em>naturally</em> (ie, in an order which seems logical to a person), rather than by characters&#8217; ordinal values. Take, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">&quot;100 apples&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;5 apples&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;110 apples&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;55 apples&quot;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// normal sorting:</span>
<span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># Outputs:
</span><span style="color: #666666; font-style: italic;"># Array
</span><span style="color: #666666; font-style: italic;"># (
</span><span style="color: #666666; font-style: italic;">#     [0] =&gt; 100 apples
</span><span style="color: #666666; font-style: italic;">#     [1] =&gt; 110 apples
</span><span style="color: #666666; font-style: italic;">#     [2] =&gt; 5 apples
</span><span style="color: #666666; font-style: italic;">#     [3] =&gt; 55 apples
</span><span style="color: #666666; font-style: italic;"># )
</span>
<span style="color: #990000;">natsort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># Outputs:
</span><span style="color: #666666; font-style: italic;"># Array
</span><span style="color: #666666; font-style: italic;"># (
</span><span style="color: #666666; font-style: italic;">#     [2] =&gt; 5 apples
</span><span style="color: #666666; font-style: italic;">#     [3] =&gt; 55 apples
</span><span style="color: #666666; font-style: italic;">#     [0] =&gt; 100 apples
</span><span style="color: #666666; font-style: italic;">#     [1] =&gt; 110 apples
</span><span style="color: #666666; font-style: italic;"># )</span></pre></div></div>

<span id="levenshtein"><h3>9. levenshtein()</h3></span>
<p><a href="http://uk.php.net/levenshtein">levenshtein()</a> tells you how &#8220;far&#8221; away two words are. It will return the minimum number of inserts, replaces and deletions needed to transform one string to the other. Take, for example, the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dictionary</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;javascript&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;css&quot;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$word</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;japhp&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$best_match</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dictionary</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$match_value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">levenshtein</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dictionary</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dictionary</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">levenshtein</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$word</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$match_value</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$best_match</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$w</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$match_value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Did you mean the '<span style="color: #006699; font-weight: bold;">$best_match</span>' category?&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this case, the user has been asked to provide a category name. They provided &#8220;japhp&#8221;, which is invalid. Since this is likely to be a typing error, the code above will make a suggestion (&#8220;Did you mean the &#8216;php&#8217; category?&#8221;).</p>
<span id="glob"><h3>10. glob()</h3></span>
<p><a href="http://uk.php.net/glob">glob()</a> will make you feel stupid after using opendir(), readdir() and closedir() to search for a file. It&#8217;s this simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">glob</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;*.php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$file</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<span id="Any_more"><h3>Any more?</h3></span>
<p>There are loads of functions out there. If you can&#8217;t get enough, <a href="http://uk2.php.net/http_build_query">http_build_query()</a>, <a href="http://uk2.php.net/register_shutdown_function">register_shutdown_function()</a> and <a href="http://uk2.php.net/pspell-suggest.php">pspell_suggest</a> are also worth a mention.What&#8217;s your favourite discovery?</p>
]]></content:encoded>
			<wfw:commentRss>http://infinity-infinity.com/2009/07/10-php-functions-you-probably-never-use/feed/</wfw:commentRss>
		<slash:comments>88</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->