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

Usage Example: FluentDOM::filter() with Closure

  1. <?php
  2. /**
  3. *
  4. @version $Id: filter-fn.php 429 2010-03-29 08:05:32Z subjective $
  5. @license http://www.opensource.org/licenses/mit-license.php The MIT License
  6. @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
  7. */
  8. header('Content-type: text/plain');
  9.  
  10. $xml = <<<XML
  11. <html>
  12. <head></head>
  13. <body>
  14.   <div id="first"></div>
  15.   <div id="second"></div>
  16.   <div id="third"></div>
  17.   <div id="fourth"></div>
  18.   <div id="fifth"></div>
  19.   <div id="sixth"></div>
  20. </body>
  21. </html>
  22. XML;
  23.  
  24. require_once('../FluentDOM.php');
  25. echo FluentDOM($xml)
  26.   ->find('//div')
  27.   ->attr('border'1)
  28.   ->filter(
  29.     function($node$index{
  30.       if ($index == ||
  31.           FluentDOM($node)->attr('id'== 'fourth'{
  32.         return TRUE;
  33.       }
  34.       return FALSE;
  35.     }
  36.   )
  37.   ->attr('style''text-align: center;');
  38. ?>

Documentation generated on Sun, 26 Sep 2010 01:00:48 +0200 by phpDocumentor 1.4.3