<?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>PHP 4u Web developer - 代码的简化 &#187; php</title>
	<atom:link href="http://php4u.co.uk/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://php4u.co.uk</link>
	<description>PHP related blog, freelancer to hire!</description>
	<lastBuildDate>Fri, 30 Jul 2010 14:13:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Prime numbers in PHP &#8211; quick and efficient way</title>
		<link>http://php4u.co.uk/2010/07/prime-numbers-in-php-quick-and-efficient-way/</link>
		<comments>http://php4u.co.uk/2010/07/prime-numbers-in-php-quick-and-efficient-way/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 08:19:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[prime numbers]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://php4u.co.uk/?p=139</guid>
		<description><![CDATA[Looking for a way to find prime numbers in php? I wfound one perl solution here, but it wasn&#8217;t perl magic &#8211; it was power of regular expressions. Please find code below which will be self-explanatory. &#60;?php /** * Function checks if given number is prime * * @param integer $n * @return boolean */ [...]]]></description>
			<content:encoded><![CDATA[<p>Looking for a way to find prime numbers in php? I wfound one perl solution <a title="Prime numbers in perl" href="http://montreal.pm.org/tech/neil_kandalgaonkar.shtml" target="_blank">here</a>, but it wasn&#8217;t perl magic &#8211; it was power of regular expressions.</p>
<p>Please find code below which will be self-explanatory.</p>
<p><code lang="php"><br />
&lt;?php</code></p>
<p>/**<br />
* Function checks if given number is prime<br />
*<br />
* @param integer $n<br />
* @return boolean<br />
*/<br />
function isPrime($n) {<br />
return (!preg_match(&#8216;/^1?$|^(11+?)\1+$/x&#8217;, str_repeat(&#8217;1&#8242;, intval($n)))) ;<br />
}</p>
<p>for ($n=0;$n&lt;100;$n++) {<br />
echo &#8220;Number {$n} is &#8220;.(isPrime($n) ? &#8216;prime&#8217; : &#8216;not prime&#8217;).&#8221;&lt;br/&gt;\n&#8221;;<br />
}</p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://php4u.co.uk/2010/07/prime-numbers-in-php-quick-and-efficient-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Run PHP (and others) code in a browser &#8211; revolutionary pastebin</title>
		<link>http://php4u.co.uk/2009/12/run-php-and-others-code-in-a-browser-revolutionary-pastebin/</link>
		<comments>http://php4u.co.uk/2009/12/run-php-and-others-code-in-a-browser-revolutionary-pastebin/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 12:52:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[code in browser]]></category>
		<category><![CDATA[code testing]]></category>
		<category><![CDATA[pastebin]]></category>

		<guid isPermaLink="false">http://php4u.co.uk/?p=112</guid>
		<description><![CDATA[If you need to test a code in browser &#8211; try  http://ideone.com/ Entry found on http://alouche.net/blog/2009/11/24/ideone-compiler-pastebin/]]></description>
			<content:encoded><![CDATA[<p>If you need to test a code in browser &#8211; try  <a href="http://ideone.com/">http://ideone.com/</a></p>
<p>Entry found on http://alouche.net/blog/2009/11/24/ideone-compiler-pastebin/</p>
]]></content:encoded>
			<wfw:commentRss>http://php4u.co.uk/2009/12/run-php-and-others-code-in-a-browser-revolutionary-pastebin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geotagging script</title>
		<link>http://php4u.co.uk/2009/08/geotagging-script/</link>
		<comments>http://php4u.co.uk/2009/08/geotagging-script/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 20:48:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[geotagging]]></category>
		<category><![CDATA[user stats]]></category>
		<category><![CDATA[visitors live stats]]></category>

		<guid isPermaLink="false">http://php4u.co.uk/?p=98</guid>
		<description><![CDATA[Geotagging script (http://themeforest.net/user/php4ucouk) Script converts visitor&#8217;s ip adress into : country code (2 and 3 letter ISO code) full english country name region code and name currency code used in this country postal code gps coordinates area code dma code metro code and BONUS overall statitics about users from different countries number or live visitors [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Geotagging script </strong>(http://themeforest.net/user/php4ucouk)</p>
<p>Script converts visitor&#8217;s ip adress into :</p>
<ul>
<li> country code (2 and 3 letter ISO code)</li>
</ul>
<ul>
<li> full english country name</li>
</ul>
<ul>
<li> region code and name</li>
</ul>
<ul>
<li> currency code used in this country</li>
</ul>
<ul>
<li> postal code</li>
</ul>
<ul>
<li> gps coordinates</li>
</ul>
<ul>
<li> area code</li>
</ul>
<ul>
<li> dma code</li>
</ul>
<ul>
<li> metro code</li>
</ul>
<p><strong>and BONUS</strong></p>
<ul>
<li> overall statitics about users from different countries</li>
</ul>
<ul>
<li> number or live visitors on your web page</li>
</ul>
<p>Data is provided to you, so you can use it (display it, store in db or do whatever you need)</p>
<p><strong><a title="Geotagging live demo" href="http://php4u.co.uk/geotagging/demo.php" target="_blank">Live demo</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://php4u.co.uk/2009/08/geotagging-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Mail problem on Ubuntu</title>
		<link>http://php4u.co.uk/2009/05/php-mail-problem-on-ubuntu/</link>
		<comments>http://php4u.co.uk/2009/05/php-mail-problem-on-ubuntu/#comments</comments>
		<pubDate>Fri, 29 May 2009 14:39:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://php4u.co.uk/?p=89</guid>
		<description><![CDATA[I&#8217;ve installed fresh version of Ubuntu 9.04 with Lamp, but I couldn&#8217;t send emails outside. Problem was SMTP auth of outgoing server, spending time found http://dbaron.org/linux/sendmail who made my day. Thanks]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve installed fresh version of Ubuntu 9.04 with Lamp, but I couldn&#8217;t send emails outside.</p>
<p>Problem was SMTP auth of outgoing server, spending time found <a title="Sendmail SMTP conf" href="http://dbaron.org/linux/sendmail" target="_blank">http://dbaron.org/linux/sendmail</a> who made my day. Thanks</p>
]]></content:encoded>
			<wfw:commentRss>http://php4u.co.uk/2009/05/php-mail-problem-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sFTP for PHP 5.xx</title>
		<link>http://php4u.co.uk/2009/03/sftp-for-php-5xx/</link>
		<comments>http://php4u.co.uk/2009/03/sftp-for-php-5xx/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 12:51:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[ssh3]]></category>

		<guid isPermaLink="false">http://php4u.co.uk/?p=62</guid>
		<description><![CDATA[Install SSh2 extension for PHP, then you can use class below: ?View Code PHP&#38;lt;?php /** * Class to deal with sFTP connections * to use install http://php.oregonstate.edu/manual/en/ssh2.installation.php * */ class SFTPConnection &#123; private $connection; private $sftp; &#160; public function __construct&#40;$host, $port=22&#41; &#123; if &#40;!extension_loaded&#40;'ssh2'&#41;&#41; &#123; throw new Exception&#40;&#34;Extension ssh2 has to be loaded to use [...]]]></description>
			<content:encoded><![CDATA[<p>Install SSh2 extension for PHP, then you can use class below:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p62code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p622"><td class="code" id="p62code2"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #009933; font-style: italic;">/**
 * Class to deal with sFTP connections
 * to use install http://php.oregonstate.edu/manual/en/ssh2.installation.php
 *
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> SFTPConnection
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$sftp</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">22</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/extension_loaded"><span style="color: #990000;">extension_loaded</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ssh2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        	<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Extension ssh2 has to be loaded to use this class. Please enable in php.ini.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    	<span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>connection <span style="color: #339933;">=</span> <a href="http://www.php.net/ssh2_connect"><span style="color: #990000;">ssh2_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</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;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>connection<span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not connect to <span style="color: #006699; font-weight: bold;">$host</span> on port <span style="color: #006699; font-weight: bold;">$port</span>.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/extension_loaded"><span style="color: #990000;">extension_loaded</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ssh2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        	<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Extension ssh2 has to be loaded to use this class. Please enable in php.ini.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #339933;">@</span><a href="http://www.php.net/ssh2_auth_password"><span style="color: #990000;">ssh2_auth_password</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>connection<span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not authenticate with username <span style="color: #006699; font-weight: bold;">$username</span> &quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;and password <span style="color: #006699; font-weight: bold;">$password</span>.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sftp <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/ssh2_sftp"><span style="color: #990000;">ssh2_sftp</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>connection<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;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sftp<span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not initialize SFTP subsystem.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> uploadFile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$local_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$remote_file</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/extension_loaded"><span style="color: #990000;">extension_loaded</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ssh2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        	<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Extension ssh2 has to be loaded to use this class. Please enable in php.ini.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    	<span style="color: #000088;">$sftp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sftp<span style="color: #339933;">;</span>
        <span style="color: #000088;">$stream</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ssh2.sftp://<span style="color: #006699; font-weight: bold;">$sftp</span><span style="color: #006699; font-weight: bold;">$remote_file</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'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: #339933;">!</span> <span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not open file: <span style="color: #006699; font-weight: bold;">$remote_file</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data_to_send</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$local_file</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;">$data_to_send</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not open local file: <span style="color: #006699; font-weight: bold;">$local_file</span>.&quot;</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><a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data_to_send</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not send data from file: <span style="color: #006699; font-weight: bold;">$local_file</span>.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #339933;">@</span><a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> scanFilesystem<span style="color: #009900;">&#40;</span><span style="color: #000088;">$remote_file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/extension_loaded"><span style="color: #990000;">extension_loaded</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ssh2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	        <span style="color: #009900;">&#123;</span>
	        	<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Extension ssh2 has to be loaded to use this class. Please enable in php.ini.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        <span style="color: #009900;">&#125;</span>
        	<span style="color: #000088;">$sftp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sftp<span style="color: #339933;">;</span>
            <span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ssh2.sftp://<span style="color: #006699; font-weight: bold;">$sftp</span><span style="color: #006699; font-weight: bold;">$remote_file</span>&quot;</span><span style="color: #339933;">;</span>
              <span style="color: #000088;">$tempArray</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/opendir"><span style="color: #990000;">opendir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #666666; font-style: italic;">// List all the files</span>
            <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/readdir"><span style="color: #990000;">readdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$file</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</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;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color: #990000;">is_dir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//                $tempArray[$file] = $this-&amp;gt;scanFilesystem(&quot;$dir/$file&quot;);</span>
               <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                 <span style="color: #000088;">$tempArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
             <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
           <a href="http://www.php.net/closedir"><span style="color: #990000;">closedir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tempArray</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>   
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> receiveFile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$remote_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$local_file</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/extension_loaded"><span style="color: #990000;">extension_loaded</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ssh2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        	<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Extension ssh2 has to be loaded to use this class. Please enable in php.ini.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    	<span style="color: #000088;">$sftp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sftp<span style="color: #339933;">;</span>
        <span style="color: #000088;">$stream</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ssh2.sftp://<span style="color: #006699; font-weight: bold;">$sftp</span><span style="color: #006699; font-weight: bold;">$remote_file</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not open file: <span style="color: #006699; font-weight: bold;">$remote_file</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fread"><span style="color: #990000;">fread</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #339933;">,</span> <a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ssh2.sftp://<span style="color: #006699; font-weight: bold;">$sftp</span><span style="color: #006699; font-weight: bold;">$remote_file</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/file_put_contents"><span style="color: #990000;">file_put_contents</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$local_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$contents</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #339933;">@</span><a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteFile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$remote_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/extension_loaded"><span style="color: #990000;">extension_loaded</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ssh2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
      	<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Extension ssh2 has to be loaded to use this class. Please enable in php.ini.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000088;">$sftp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sftp<span style="color: #339933;">;</span>
      <a href="http://www.php.net/unlink"><span style="color: #990000;">unlink</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ssh2.sftp://<span style="color: #006699; font-weight: bold;">$sftp</span><span style="color: #006699; font-weight: bold;">$remote_file</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://php4u.co.uk/2009/03/sftp-for-php-5xx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP CLI Progress Indicator</title>
		<link>http://php4u.co.uk/2009/03/php-cli-progress-indicator/</link>
		<comments>http://php4u.co.uk/2009/03/php-cli-progress-indicator/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 12:37:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[progress bar]]></category>

		<guid isPermaLink="false">http://php4u.co.uk/?p=58</guid>
		<description><![CDATA[Today I wanted to create some progress indicator PHP command line, after minute googling I found http://forums.devshed.com/php-development-5/php-cli-progress-indicator-151590.html After slight change: ?View Code PHPfunction progressBar&#40;$current, $total, $label&#41; &#123; $percent = round&#40;$current / $total * 100&#41;; &#160; if &#40;$current == 0&#41; &#123; if &#40;$label == &#34;&#34;&#41; echo &#34;Progress: \n&#34;; else if &#40;$label != &#34;none&#34;&#41; echo $label.&#34;\n&#34;; echo [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wanted to create some progress indicator PHP command line, after minute googling I found <a title="Progress indicator" href="http://forums.devshed.com/php-development-5/php-cli-progress-indicator-151590.html" target="_blank">http://forums.devshed.com/php-development-5/php-cli-progress-indicator-151590.html</a></p>
<p>After slight change:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p58code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p584"><td class="code" id="p58code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> progressBar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #339933;">,</span> <span style="color: #000088;">$total</span><span style="color: #339933;">,</span> <span style="color: #000088;">$label</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$percent</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$total</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">100</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;">$current</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$label</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Progress: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$label</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$label</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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;|&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$place</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span> <span style="color: #000088;">$place</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>gt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$place</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\010</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$place</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$place</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span> <span style="color: #000088;">$place</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$place</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>lt<span style="color: #339933;">;=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$percent</span><span style="color: #339933;">*</span><span style="color:#800080;">0.15</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;| &quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%3.0f'</span><span style="color: #339933;">,</span><span style="color: #000088;">$percent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;%&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$total</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://php4u.co.uk/2009/03/php-cli-progress-indicator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.007 seconds -->
