当前位置:Gxlcms > PHP教程 > DOMElement获取带html标签的内容

DOMElement获取带html标签的内容

时间:2021-07-01 10:21:17 帮助过:122人阅读

如题

DOMElement Object
(
    [tagName] => div
    [schemaTypeInfo] => 
    [nodeName] => div
    [nodeValue] => 
    Article Name
    Contents of article
    One
      Two
      Three
      Four
      Five

    [nodeType] => 1
    [parentNode] => (object value omitted)
    [childNodes] => (object value omitted)
    [firstChild] => (object value omitted)
    [lastChild] => (object value omitted)
    [previousSibling] => 
    [attributes] => (object value omitted)
    [ownerDocument] => (object value omitted)
    [namespaceURI] => 
    [prefix] => 
    [localName] => div
    [baseURI] => 
    [textContent] => 
    Article Name
    Contents of article
    One
      Two
      Three
      Four
      Five

)

用textContent获取的都是不带标签的内容...不知有木有php自带方法可以实现的?

回复内容:

如题

DOMElement Object
(
    [tagName] => div
    [schemaTypeInfo] => 
    [nodeName] => div
    [nodeValue] => 
    Article Name
    Contents of article
    One
      Two
      Three
      Four
      Five

    [nodeType] => 1
    [parentNode] => (object value omitted)
    [childNodes] => (object value omitted)
    [firstChild] => (object value omitted)
    [lastChild] => (object value omitted)
    [previousSibling] => 
    [attributes] => (object value omitted)
    [ownerDocument] => (object value omitted)
    [namespaceURI] => 
    [prefix] => 
    [localName] => div
    [baseURI] => 
    [textContent] => 
    Article Name
    Contents of article
    One
      Two
      Three
      Four
      Five

)

用textContent获取的都是不带标签的内容...不知有木有php自带方法可以实现的?

这个能返回带标签的内容,应该是你要找的吧?:http://cn2.php.com/manual/zh/domdocument.savehtml.php

如果是XML的话最好用saveXML

人气教程排行