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

FluentDOM\Query::wrapAll()

FluentDOM\Query wrapAll(string|array|\DOMNode|\Traversable|callable $content);

Wrap al matched elements with the specified content. If the matched elements are not siblings, wrap each group of siblings.

Usage

$html = <<<HTML
<html>
  <head>
    <title>Examples: FluentDOM\Query::wrapAll()</title>
  </head>
  <body>
    <div>
      <p>Hello</p>
      <p>cruel</p>
    </div>
    <div>
      <p>World</p>
    </div>
  </body>
</html>
HTML;

echo FluentDOM($html)
  ->find('//p')
  ->wrapAll('<div class="wrapper" />');

Output

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