• PHP script tweak, Need help ><
    5 replies, posted
Is there a way to load the whole page, then load the $total_time in the middle? Normally nothing will show because the end of the script has not been possessed. The php is from phpjabbers but getting a reply seems unlikely, and more than one person has asked this question and not gotten a reply. [code] <html> <?php $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time; ?> <head> HEAD CONTENT </head> <body> PAGE CONTENT <?php echo $total_time ?> MORE CONTENT </body> <?php $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4); ?> </html> [/code]
Not really, not with pure PHP. You could have an empty element, and then right at the end of the document. print out some Javascript that printed the text into that element after document.ready.
Ok, i'll read up and try it.
How about this: [code] <html> <?php $start = getTime(); ?> <head> HEAD CONTENT </head> <body> <p> PAGE CONTENT </p> <p> MORE CONTENT </p> <div id="totaltime"> </div> <script type="text/javascript"> <?php $finish = getTime(); $total_time = round(($finish - $start), 4); ?> document.getElementById("totaltime").innerHTML = "<?= $totaltime ?>"; </script> </body> </html> <?php function getTime() { $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; return $time; } ?> [/code] Note that, this only gets the page load on the server, not the actual pageload time (since your browser has to request the page, and render it too).
Output buffering. [PHP] <?php $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time; ob_start(); ?> <html> <head> HEAD CONTENT </head> <body> PAGE CONTENT [#TOTALTIME#] MORE CONTENT </body> </html> <?php $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4); $output = ob_get_contents(); ob_end_clean(); $output = str_replace('[#TOTALTIME#]', $total_time, $output); echo $output; ?> [/PHP] Unless there is more PHP between there is no point doing this.
Theres a lot of php between the the 2, I just wanted to make the example as clean as possible. [editline]8th May 2013[/editline] Works Flawlessly, Thank you CBastard!!!!
Sorry, you need to Log In to post a reply to this thread.