You are here

public function QueryPath::textBefore in QueryPath 6

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

File

QueryPath/QueryPath.php, line 1264

Class

QueryPath

Code

public function textBefore($text = NULL) {
  if (isset($text)) {
    $textNode = $this->document
      ->createTextNode($text);
    return $this
      ->before($textNode);
  }
  $buffer = '';
  foreach ($this->matches as $m) {
    $p = $m;
    while (isset($p->previousSibling) && $p->previousSibling->nodeType == XML_TEXT_NODE) {
      $p = $p->previousSibling;
      $buffer .= $p->textContent;
    }
  }
  return $buffer;
}