Query Slice - ThomasWeinert/FluentDOM GitHub Wiki
FluentDOM\Query slice(int $start [, int $end = NULL])
Selects a subset of the matched elements.
$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');
<?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>