PHP和jQuery进度条在解析进度条、PHP、jQuery

2023-09-10 13:30:29 作者:拿稳我心你称王

我想知道我怎么能去制作一个进度条解析HTML数据。本质上,用户搜索的东西,我解析另一个网站。我试图与得到以阵列然后除以100由它已找到对象的量,并获得当前的在for循环中,它由100 /总乘以这样做。然后,我将更新与值的文本文件。然后更新与该值的进度条。不过,我希望有一个更有效的方法来做到这一点。此外,它必须是唯一的每个用户。谢谢你。

I was wondering how I could go about making a progress bar for parsing HTML data. Essentially the user searches something and I parse another website. I tried doing it with getting the amount of objects found in an array then dividing 100 by it, and getting the current one in a for loop and multiplying it by 100/total. Then I would update a text file with the value. Then update the progress bar with that value. However, I want a more efficient way to do it. Also it has to be unique to each user. Thanks.

推荐答案

我发现了另一种方式来做到这一点,这是为了帮助所有的人有同样的问题。我发现它在这里http://w3shaman.com/article/php-progress-bar-script

I found another way to do it, this is to help all of those people that have the same question. I found it out on here 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>
?>