+ -
当前位置:首页 → 问答吧 → 我想要的效果是它在这个框里输出的时候始终看到的是最后输出的信息

我想要的效果是它在这个框里输出的时候始终看到的是最后输出的信息

时间:2011-12-04

来源:互联网

PHP code

php 输出到textarea 滚动条自动向下移动

<?php 
 class runtime 
 {  
     var $StartTime = 0;  
     var $StopTime = 0;  
   
     function get_microtime()  
     {  
         list($usec, $sec) = explode(' ', microtime());  
         return ((float)$usec + (float)$sec);  
     }  
   
     function start()  
     {  
         $this->StartTime = $this->get_microtime();  
     }  
   
     function stop()  
     {  
         $this->StopTime = $this->get_microtime();  
     }  
   
     function spent()  
     {  
         return round(($this->StopTime - $this->StartTime) * 1000, 1);  
     }  
   
 } 
   
   
  
 $runtime= new runtime; 
 
   

   echo '
   <textarea   rows= "5 "   cols= "20 "   id= "ScrollText "> 
 ';
 set_time_limit(0);
ob_end_flush();
for($i = 0; $i<100000; $i++){
     $runtime->start();
    sleep(1);
    //usleep(1000000);
    echo $i."\n";
    flush();
     $runtime->stop(); 
 echo "执行时间: ".$runtime->spent()." 毫秒\n"; 
}

echo '</textarea>';
 
 ?> 


作者: muyilongh   发布时间: 2011-12-04

try:
PHP code

set_time_limit(0);

for($i = 0; $i<100000; $i++){
     $runtime->start();
     echo $i."\n";

     flush();
     ob_flush();
     usleep(250000);
     $runtime->stop(); 
 echo "执行时间: ".$runtime->spent()." 毫秒\n"; 
}
ob_end_flush();

作者: xiaofanku   发布时间: 2011-12-04

热门下载

更多