login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Snippets > Perfecte parsetijd weergave

Perfecte parsetijd weergave

Auteur: Richard - 25 februari 2006 - 16:01 - Gekeurd door: nemesiskoen - Hits: 3097 - Aantal punten: (0 stemmen)



Ik vind het zelf behoorlijk ergerlijk dat ik voor parsetijd weergave het nooit precies aan het einde van de pagina kan weergeven, heb ik een simpele snippet gemaakt die dit mogelijk maakt met een placeholder.

Code:
  1. <?php
  2. /**
  3.  * @package parsetime
  4.  * @author JeXuS <jexus@jexus.net>
  5.  * @filesource
  6. **/
  7.  
  8.  
  9. /**
  10.  * Return normal microtime in float format
  11.  *
  12.  * @return float
  13.  * @access public
  14. **/
  15. function get_microtime ()
  16. {
  17. return array_sum (explode (' ', microtime ()));
  18. }
  19.  
  20. /**
  21.  * output buffer function, replaces placeholder with real time
  22.  *
  23.  * @param string data returned from ob
  24.  * @return string
  25.  * @access private
  26. **/
  27. function _ob_parsetime_replacer ($data)
  28. {
  29. // the current time
  30. $time = number_format (get_microtime () - $GLOBALS['parse_time'], 5);
  31. // the placeholder
  32. $_placeholder = '{|**PARSE_TIME_PLACE**|}';
  33.  
  34. // position of the placeholder
  35. $pos = strrpos ($data, $_placeholder);
  36.  
  37. // replace that substring with the time
  38. return substr_replace ($data, $time, $pos, strlen ($_placeholder));
  39. }
  40.  
  41. /**
  42.  * holds first microtime
  43.  *
  44.  * @global float $GLOBALS['parse_time']
  45.  * @access private
  46. **/
  47. $GLOBALS['parse_time'] = get_microtime ();
  48.  
  49. ob_start ('_ob_parsetime_replacer');
  50. ?>


en nu ergens in je html:

  1. {|**PARSE_TIME_PLACE**|}
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (11)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.035s