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

Usage Example: FluentDOM::text()

  1. <?php
  2. /**
  3. *
  4. @version $Id: text.php 322 2009-09-14 20:19:48Z 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>
  15.     <p>Hello</p>
  16.     <p>cruel</p>
  17.     <p>World!</p>
  18.   </div>
  19. </body>
  20. </html>
  21. XML;
  22.  
  23. require_once('../FluentDOM.php');
  24.  
  25. /*
  26.  * replace text content of 2nd paragraph
  27.  */
  28. echo FluentDOM($xml)
  29.   ->find('//p[position() = 2]')
  30.   ->text('nice');
  31.  
  32. echo "\n\n";
  33.  
  34. /*
  35.  * replace text content of every paragraph
  36.  */
  37. echo FluentDOM($xml)
  38.   ->find('//p')
  39.   ->text('nice');
  40.  
  41. echo "\n\n";
  42.  
  43. /*
  44.  * This explict example is to verify a PHP 'malloc' error thrown on MacOsX 10.5.7
  45.  * when running test with PHPUnit3.3 - unfortunately it won't appear here
  46.  *
  47.  * replace text content of 2nd paragraph
  48.  */
  49. echo FluentDOM($xml)
  50.   ->find('//p[position() = 1]')
  51.   ->next()
  52.   ->text('nice');
  53. ?>

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