首页 > 建站教程 > PHP教程 >  PHP 进度条函数的简单实例_php技巧正文

PHP 进度条函数的简单实例_php技巧

PHP 进度条函数的简单实例

其实进度条的做法很简单的。网上的一大堆,自己写了一个,哈哈,感觉看起来很有感觉。

实例代码:

01function ShowPercent($now,$total)
02{
03 $percent = sprintf('%.0f',$now*100/$total);
04 $html = '<table width="60%" style="border-collapse:separate" height="10" border="0" cellpadding="0" cellspacing="2" bgcolor="#fff"><tr>';
05 $count=0;
06 $pertr = 30;
07 while($count < $total)
08 {
09  $bgcolor = $count < $now ? 'green':'#EEEEEE';
10  $html .= '<td bgcolor="'.$bgcolor.'"> </td>';
11  $count++;
12  if($count%$pertr == 0) $html .= '</tr><tr>';
13 }
14 $bgcolor2 = $now == $total ? ' style="font-weight:bold;color:green;"':'';
15 $html .= '<td'.$bgcolor2.' colspan="'.($count%$pertr).'">'.$percent.'%</td></tr></table>';
16 return $html;
17}

效果截图: 100%的时候。

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!