PHP DOM get nodevalue html? (without stripping tags)

前端 未结 2 1187
面向向阳花
面向向阳花 2020-12-01 03:29

I am trying to get the innerhtml of div tags in a file using nodeValue, however this code is outputting only plain text and seems to strip out all html tag from inside the d

2条回答
  •  青春惊慌失措
    2020-12-01 04:18

    I have never done what you're attempting to do, but as a stab in the dark, using the API docs, does echo $entry->textContent; work?

    Adding an update. This is from the comments located on the docs page for DOMNode:

    Hi!

    Combining all th comments, the easiest way to get inner HTML of the node is to use this function:

    childNodes; 
        foreach ($children as $child) { 
            $innerHTML .= $child->ownerDocument->saveXML( $child ); 
        } 
    
        return $innerHTML;  }  ?>
    

    Or, maybe a simpler method is just to do:

    echo $domDocument->saveXML($entry);
    

提交回复
热议问题