<?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; cli</title>
	<atom:link href="http://php4u.co.uk/tag/cli/feed/" rel="self" type="application/rss+xml" />
	<link>http://php4u.co.uk</link>
	<description>PHP related blog, freelancer to hire!</description>
	<lastBuildDate>Fri, 27 Aug 2010 12:09:42 +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>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('p58code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p582"><td class="code" id="p58code2"><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 0.751 seconds -->
