php DomDocument adds extra tags

后端 未结 5 715
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 03:09

I\'m trying to parse a document and get all the image tags and change the source for something different.


    $domDocument = new DOMDocument();

    $domDo         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 04:02

    If you're going to save as HTML, you have to expect a valid HTML document to be created!

    There is another option: DOMDocument::saveXML has an optional parameter allowing you to access the XML content of a particular element:

    $el = $domDocument->getElementsByTagName('p')->item(0);
    $text = $domDocument->saveXML($el);
    

    This presumes that your content only has one p element.

提交回复
热议问题