Skip to content
Thomas Weinert edited this page Jul 30, 2014 · 1 revision

FluentDOM\Query::slice()

FluentDOM\Query slice(int $start [,  int $end = NULL])

Selects a subset of the matched elements.

Usage

$html = <<<HTML
<html>
  <head>
    <title>Examples: FluentDOM\Query::slice()</title>
  </head>
  <body>
    <div>
      <p>Hello</p>
      <p>cruel</p>
      <p>World!</p>
      <p>I am</p>
      <p>leaving</p>
      <p>you today!</p>
    </div>
  </body>
</html>
HTML;

echo FluentDOM($html)
  ->find('//p')
  ->slice(0, 3)
  ->replaceAll('//div');

Output

<?xml version="1.0"?>
<html>
  <head>
    <title>Examples: FluentDOM\Query::slice()</title>
  </head>
  <body>
    <p>Hello</p><p>cruel</p><p>World!</p>
  </body>
</html>
Clone this wiki locally