fork(1) download
  1. <?php
  2.  
  3. function example($attr) {
  4. return preg_match('/post-(content|[a-z]+)/i', $attr) > 0;
  5. }
  6. $html = <<<HTML
  7. <body>
  8. <div class='post-body entry-content' id='post-body-37'>
  9. <div style="text-align: left;">
  10. <div style="text-align: center;">
  11. Hi
  12. </div></div></div>
  13. </body>
  14. HTML;
  15. $dom = new DOMDocument;
  16. $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD);
  17.  
  18. $xp = new DOMXPath($dom);
  19. $xp->registerNamespace("php", "h"."ttp://php.net/xpath");
  20. $xp->registerPHPFunctions('example');
  21. $divs = $xp->query("//div[php:functionString('example', @class)]");
  22. foreach ($divs as $div) {
  23. echo $div->nodeValue;
  24. }
Success #stdin #stdout 0.02s 25020KB
stdin
Standard input is empty
stdout

Hi