解析时PHP和jQuery进度条

Use*_*ame 4 javascript php ajax jquery progress-bar

我想知道如何制作解析HTML数据的进度条.基本上用户搜索的东西,我解析另一个网站.我尝试通过获取在数组中找到的对象数量然后将100除以它,并将当前的一个在for循环中并将其乘以100 /总计来实现.然后我会用值更新文本文件.然后使用该值更新进度条.但是,我想要一种更有效的方法来做到这一点.此外,它必须是每个用户独有的.谢谢.

Use*_*ame 6

我找到了另一种方法,这是为了帮助那些有同样问题的人.我在这里找到了它http://w3shaman.com/article/php-progress-bar-script

<?php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>Progress Bar</title>
</head>
<body>
<!-- Progress bar holder -->
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
<?php
// Total processes
$total = 10;
// Loop through process
for($i=1; $i<=$total; $i++){
    // Calculate the percentation
    $percent = intval($i/$total * 100)."%";

    // Javascript for updating the progress bar and information
    echo '<script language="javascript">
    document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
    document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
    </script>';


// This is for the buffer achieve the minimum size in order to flush data
    echo str_repeat(' ',1024*64);


// Send output to browser immediately
    flush();


// Sleep one second so we can see the delay
    sleep(1);
}
// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
?>
</body>
</html>
?>
Run Code Online (Sandbox Code Playgroud)