public function QueryPath::wrapAll in QueryPath 6
Same name and namespace in other branches
- 7.3 QueryPath/QueryPath.php \QueryPath::wrapAll()
- 7.2 QueryPath/QueryPath.php \QueryPath::wrapAll()
File
- QueryPath/
QueryPath.php, line 793
Class
Code
public function wrapAll($markup) {
if ($this->matches
->count() == 0) {
return;
}
$data = $this
->prepareInsert($markup);
if (empty($data)) {
return $this;
}
if ($data
->hasChildNodes()) {
$deepest = $this
->deepestNode($data);
$bottom = $deepest[0];
}
else {
$bottom = $data;
}
$first = $this
->getFirstMatch();
$parent = $first->parentNode;
$parent
->insertBefore($data, $first);
foreach ($this->matches as $m) {
$bottom
->appendChild($m->parentNode
->removeChild($m));
}
return $this;
}