Home  >  Article  >  Backend Development  >  A simple example of PHP progress bar function

A simple example of PHP progress bar function

小云云
小云云Original
2018-01-10 17:01:511369browse

This article mainly introduces relevant information about simple examples of PHP progress bar function. I hope this article can help everyone. Friends in need can refer to it. I hope it can help everyone.

Simple example of PHP progress bar function

In fact, the progress bar is very simple. There are a lot of them on the Internet, so I wrote one myself, haha, I think it looks very interesting.

Instance code:


function ShowPercent($now,$total) 
{ 
 $percent = sprintf('%.0f',$now*100/$total); 
 $html = &#39;<table width="60%" style="border-collapse:separate" height="10" border="0" cellpadding="0" cellspacing="2" bgcolor="#fff"><tr>&#39;; 
 $count=0; 
 $pertr = 30; 
 while($count < $total) 
 { 
  $bgcolor = $count < $now ? &#39;green&#39;:&#39;#EEEEEE&#39;; 
  $html .= &#39;<td bgcolor="&#39;.$bgcolor.&#39;"> </td>&#39;; 
  $count++; 
  if($count%$pertr == 0) $html .= &#39;</tr><tr>&#39;; 
 } 
 $bgcolor2 = $now == $total ? &#39; style="font-weight:bold;color:green;"&#39;:&#39;&#39;; 
 $html .= &#39;<td&#39;.$bgcolor2.&#39; colspan="&#39;.($count%$pertr).&#39;">&#39;.$percent.&#39;%</td></tr></table>&#39;; 
 return $html; 
}

Effect screenshot: 100% of the time.

Related recommendations:

jquery web page loading progress bar implementation method

How to display the HTML5 Ajax file upload progress bar

Ajax method to implement the loading progress bar

The above is the detailed content of A simple example of PHP progress bar function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn