innertext() public method

get dom node's inner html
public innertext ( )
コード例 #1
0
/**
 * @param simple_html_dom_node $child
 * @param string $tmpBuffer
 * @return string
 */
function elementHandler($child, $tmpBuffer, $depth = 0, $break = true)
{
    //foreach ($childsHtml->children as $child) {
    /** @var simple_html_dom_node $child */
    if ($child->tag == 'ul') {
        foreach ($child->children as $grandchild) {
            $tmpBuffer = elementHandler($grandchild, $tmpBuffer, $depth + 1);
        }
        return $tmpBuffer;
    }
    $inner = $child->innertext();
    $break2 = true;
    if ($child->tag == 'li') {
        //$tmpBuffer.='*';
        for ($i = 0; $i < $depth; $i++) {
            $tmpBuffer .= '*';
        }
        if ($inner == '') {
            $break2 = false;
        } else {
            $tmpBuffer .= $inner;
        }
    } else {
        if ($child->tag == 'p') {
            $inner = str_replace("\t", '', $inner);
            $inner = str_replace("\n", ' ', $inner);
            //$tmpBuffer .= $inner;
            $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
        } else {
            if ($child->tag == 'b') {
                $tmpBuffer .= '===';
                $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
                //$tmpBuffer .= $inner;
                $tmpBuffer .= "===";
            } else {
                if ($child->tag == 'u') {
                    $tmpBuffer .= '<u>';
                    $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
                    //$tmpBuffer .= $inner;
                    $tmpBuffer .= '</u>';
                } else {
                    if ($child->tag == 'i') {
                        $tmpBuffer .= '\'\'';
                        $tmpBuffer = depthTest($inner, $child, $tmpBuffer);
                        //$tmpBuffer .= $inner;
                        $tmpBuffer .= '\'\'';
                    } else {
                        if ($child->tag == 'text') {
                            $tmpBuffer .= $inner;
                        } else {
                            if ($child->tag == 'font') {
                                $tmpBuffer .= $inner;
                            }
                        }
                    }
                }
            }
        }
    }
    if ($break && $break2) {
        $tmpBuffer .= "\n";
    }
    //}
    return $tmpBuffer;
}
コード例 #2
0
ファイル: DOMParser.php プロジェクト: algolia/php-dom-parser
 /**
  * @param \simple_html_dom_node $node
  *
  * @return mixed|string
  */
 private function getAttributeValue(\simple_html_dom_node $node)
 {
     // Prepare text output.
     $text = $node->innertext();
     $text = strip_tags($text);
     $text = str_replace('&nbsp;', ' ', $text);
     $text = mb_ereg_replace('\\s+', ' ', $text);
     $text = trim($text);
     return $text;
 }
コード例 #3
0
 function __get($name)
 {
     switch ($name) {
         case 'outertext':
             return $this->root->innertext();
         case 'innertext':
             return $this->root->innertext();
         case 'plaintext':
             return $this->root->text();
         case 'charset':
             return $this->_charset;
         case 'target_charset':
             return $this->_target_charset;
     }
 }
コード例 #4
0
ファイル: ListDiffLines.php プロジェクト: caxy/php-htmldiff
 /**
  * @param \simple_html_dom_node $node
  *
  * @return string
  */
 protected function getRelevantNodeText($node)
 {
     if (!$node->hasChildNodes()) {
         return $node->innertext();
     }
     $output = '';
     foreach ($node->nodes as $child) {
         /* @var $child \simple_html_dom_node */
         if (!$child->hasChildNodes()) {
             $output .= $child->outertext();
         } elseif (in_array($child->nodeName(), static::$listContentTags, true)) {
             $output .= sprintf('<%1$s>%2$s</%1$s>', $child->nodeName(), $this->getRelevantNodeText($child));
         }
     }
     return $output;
 }