您现在的位置是:网站首页>后端技术>PHP教程PHP教程

php实现进度条原理

神夜2019-09-08 12:04:51PHP教程4100人已围观文章来源:PHP中文网

简介php实现进度条的原理就是模版替换,在页面设置一个标识,轮子自己的页面,不发请求给服务器,由服务器端获得进度,然后替换该页面标识,达到进度条的效果。

PHP实现进度条的原理:

模版替换,在页面设置一个标识,轮子自己的页面,不发请求给服务器,由服务器端获得进度,然后替换该页面标识,达到进度条效果。

页面代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Lang" content="en">
<meta name="author" content="">
<meta http-equiv="Reply-to" content="@.com">
<meta name="generator" content="PhpED 5.8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="creation-date" content="01/01/2009">
<meta name="revisit-after" content="15 days">
<title>进度条</title>
<script type="jquery.min.js"></script>
<script type="text/javascript">
function test(){
    location.reload();
    setTimeOut('test()',1000)
}
</script>
</head>
 
<body οnlοad="test()">
  <div id="test">0</div>
  
  <div id="" style="width: 100;">{%a%}</div>
</body>
</html>

服务器代码

<?php
 
 for($i = 0;$i < 6;$i++){
      echo $i.'<br/>';
      echo str_repeat('      ' ,2024);
      $url = '/t/test.php';
      header("Location: " . $url.'&id='.$i);
      $read_url = realpath('.'.$url);
      $content = file_get_contents('D:/phpnow/htdocs11/design/t/test.php');
     $rr = preg_replace('/{%(.*)%}/','{%'.$i.'%}',$content);
     file_put_contents('D:/phpnow/htdocs11/design/t/test.php',$rr);
      ob_flush();
      flush();
      sleep(1);
  }

?>

以上就是php实现进度条原理的详细内容,更多请关注php中文网其它相关文章!

站点信息

  • 建站时间:2017-10-24
  • 网站程序:Hsycms 3.0
  • 文章统计:511条
  • 微信公众号:扫描二维码,关注我们