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

FluentDOM\Query::replaceWith()

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

Replaces all matched elements with the specified HTML or DOM elements. This returns the element that was just replaced, which has been removed from the DOM.

Usage

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

echo FluentDOM($html)
  ->find('//p')
  ->replaceWith('<b>Paragraph. </b>');

Output

<?xml version="1.0"?>
<html>
  <head>
    <title>Examples: FluentDOM\Query::replaceWith()</title>
  </head>
  <body>
    <b>Paragraph. </b>
    <b>Paragraph. </b>
    <b>Paragraph. </b>
  </body>
</html>
Clone this wiki locally