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

Usage Example: FluentDOM::slice()

  1. <?php
  2. /**
  3. *
  4. @version $Id: slice.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>
  15.     <p>Hello</p>
  16.     <p>cruel</p>
  17.     <p>World!</p>
  18.     <p>I am</p>
  19.     <p>leaving</p>
  20.     <p>you today!</p>
  21.   </div>
  22. </body>
  23. </html>
  24. XML;
  25.  
  26. require_once('../FluentDOM.php');
  27.  
  28. /*
  29.  * get first 3 paragraphs of the document and replace every <div> element with them
  30.  */
  31. echo FluentDOM($xml)
  32.   ->find('//p')
  33.   ->slice(03)
  34.   ->replaceAll('//div');
  35.  
  36. echo "\n\n";
  37.  
  38. echo FluentDOM($xml)
  39.   ->find('//p')
  40.   ->slice(52)
  41.   ->replaceAll('//div');
  42.  
  43. echo "\n\n";
  44.  
  45. echo FluentDOM($xml)
  46.   ->find('//p')
  47.   ->slice(1-2)
  48.   ->replaceAll('//div');
  49.  
  50. echo "\n\n";
  51.  
  52. /*
  53.  * get all paragraphs after the first 3 of the document and replace every <div> element with them
  54.  */
  55. echo FluentDOM($xml)
  56.   ->find('//p')
  57.   ->slice(3)
  58.   ->replaceAll('//div');
  59.  
  60. ?>

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