You are here

public function QueryPath::wrapInner in QueryPath 6

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

File

QueryPath/QueryPath.php, line 819

Class

QueryPath

Code

public function wrapInner($markup) {
  $data = $this
    ->prepareInsert($markup);
  if (empty($data)) {
    return $this;
  }
  if ($data
    ->hasChildNodes()) {
    $deepest = $this
      ->deepestNode($data);
    $bottom = $deepest[0];
  }
  else {
    $bottom = $data;
  }
  foreach ($this->matches as $m) {
    if ($m
      ->hasChildNodes()) {
      while ($m->firstChild) {
        $kid = $m
          ->removeChild($m->firstChild);
        $bottom
          ->appendChild($kid);
      }
    }
    $m
      ->appendChild($data);
  }
  return $this;
}