QueryPath\DOMQuery::textBefore PHP Method

textBefore() public method

If $text is passed in, the text is inserted before each currently selected item. If no text is given, this will return the concatenated text after each selected element.
public textBefore ( string $text = null ) : mixed
$text string If this is set, it will be inserted before each node in the current set of selected items.
return mixed Returns the DOMQuery object if $text was set, and returns a string (possibly empty) if no param is passed.
    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;
    }