XML_HTMLSax3
[ class tree: XML_HTMLSax3 ] [ index: XML_HTMLSax3 ] [ all elements ]

Source for file ExpatvsHtmlSax.php

Documentation is available at ExpatvsHtmlSax.php

  1. <?php
  2. /**
  3. @version $Id: ExpatvsHtmlSax.php,v 1.3 2004/06/02 14:33:38 hfuecks Exp $
  4. *  Shows HTMLSax in a race against Expat. Note that HTMLSax performance
  5. *  gets slower on PHP < 4.3.0 or if parser options are being used
  6. */
  7. require_once('XML/HTMLSax3.php');
  8.  
  9. function getmicrotime()
  10.     list($usec$secexplode(" ",microtime())
  11.     return ((float)$usec + (float)$sec)
  12. }
  13.  
  14. // The PHP general RDF feed
  15. $doc file_get_contents('http://news.php.net/group.php?group=php.general&format=rdf');
  16.  
  17. /* Simple handler that does nothing */
  18. class MyHandler {
  19.     function openHandler($parser,$name,$attrs{}
  20.     function closeHandler($parser,$name{}
  21.     function dataHandler($parser,$data{}
  22. }
  23. $handler=new MyHandler();
  24.  
  25.  
  26. $parser xml_parser_create();
  27. xml_set_object($parser$handler);
  28. xml_set_element_handler($parser'openHandler''closeHandler' );
  29. xml_set_character_data_handler($parser'dataHandler' );
  30.  
  31. echo ('<pre>');
  32. // Time Expat
  33. $start getmicrotime();
  34. xml_parse($parser$doc);
  35. $end getmicrotime();
  36. echo "Expat took:\t\t".(getmicrotime()-$start)."<br />" );
  37.  
  38. $start getmicrotime();
  39. $parser =new XML_HTMLSax3();
  40. $parser->set_object($handler);
  41. $parser->set_element_handler('openHandler','closeHandler');
  42. $parser->set_data_handler('dataHandler');
  43.  
  44. // Time HTMLSax
  45. $start getmicrotime();
  46. $parser->parse($doc);
  47. echo "HTMLSax took:\t\t".(getmicrotime()-$start) );
  48. echo ('</pre>');
  49. ?>

Documentation generated on Mon, 11 Mar 2019 15:11:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.