note 95465 deleted from function.sleep by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 Jan 2010 17:20:08 +0000 |
| Subject: | note 95465 deleted from function.sleep by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164628@lists.php.net to get a copy of this message | ||
Note Submitter: Shotokan at z0n3-h4ck dot net
----
Hello coders, I've edited the mohd code, to have a "clean output" without any
visualization of $buffer content.
<?php
ob_start();
ob_implicit_flush(true);
//[ OR ] echo "..."; ob_flush(); flush();
set_time_limit(0);
function sleep_echo($secs) {
$secs = (int) $secs;
$buffer = str_repeat("\0", 4096); // '\0' is the end of string char, so
it's not visible.
//echo $buffer."\r\n<br />\r\n";
for ($i=0; $i<$secs; $i++) {
echo date("H:i:s", time())." (".($i+1).")"."\r\n<br
/>\r\n<div style='display:none'>".$buffer."</div>\r\n<br
/>\r\n"; //invisible output
ob_flush();
flush();
sleep(1);
//usleep(1000000);
}
}
sleep_echo(30);
ob_end_flush();
?>
In this way, we've an output as this:
17:58:25 (1)
17:58:26 (2)
17:58:27 (3)
17:58:28 (4)
17:58:29 (5)
and the HTML code it makes it's:
17:58:25 (1)
<br>
<div style="display: none;"></div>
<br>
17:58:26 (2)
<br>
<div style="display: none;"></div>
<br>
17:58:27 (3)
<br>
<div style="display: none;"></div>
<br>
17:58:28 (4)
<br>
<div style="display: none;"></div>
<br>
17:58:29 (5)
<br>
<div style="display: none;"></div>
<br>
so it's really a clean code, no char added :)
Hope you n'joy this!