You are here

public function QueryPath::wrap in QueryPath 7.2

Same name and namespace in other branches
  1. 6 QueryPath/QueryPath.php \QueryPath::wrap()
  2. 7.3 QueryPath/QueryPath.php \QueryPath::wrap()

File

QueryPath/QueryPath.php, line 764

Class

QueryPath

Code

public function wrap($markup) {
  $data = $this
    ->prepareInsert($markup);
  if (empty($data)) {
    return $this;
  }
  foreach ($this->matches as $m) {
    $copy = $data->firstChild
      ->cloneNode(TRUE);
    if ($copy
      ->hasChildNodes()) {
      $deepest = $this
        ->deepestNode($copy);
      $bottom = $deepest[0];
    }
    else {
      $bottom = $copy;
    }
    $parent = $m->parentNode;
    $parent
      ->insertBefore($copy, $m);
    $m = $parent
      ->removeChild($m);
    $bottom
      ->appendChild($m);
  }
  return $this;
}