Is there a way to keep entities intact while parsing html with DomDocument?

后端 未结 3 1001
孤街浪徒
孤街浪徒 2020-12-10 06:56

I have this function to ensure every img tag has absolute URL:

function absoluteSrc($html, $encoding = \'utf-8\')
{
    $dom = new DOMDocume         


        
3条回答
  •  萌比男神i
    2020-12-10 07:38

    An alternative solution is to use DOMDocument->saveHTMLFile() (which doesn't convert HTML entities) and read the contents of the saved file back into a string.

    It's not super pretty, but it has the advantage of not having to manually find-and-replace entity codes yourself (twice) as per some other solutions proffered here.

提交回复
热议问题