Reputation: 490263
I have selected 2 elements (siblings) using PHP's DOMDocument (with a little help of DOMXPath).
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = FALSE;
$dom->loadHTML($content);
$xpath = new DOMXPath($dom);
$query = '//h3[text() = "Amenities"]';
$title = $xpath->query($query)->item(0);
$list = $title->nextSibling;
This gets me the h3
title ($title
) and the ul
list ($list
).
I want to wrap them with a div
, and add an id
.
I'm sure I can do the id
part, but I'm not sure how to wrap these elements in DOMDocument.
Would I?
div
element h3
and ul
) and insert them as children of newly created div
h3
and ul
)Is there a more straightforward way to do this?
Upvotes: 0
Views: 1578
Reputation: 23216
You can use the appendChild()
method to move an existing node. So:
Upvotes: 2