DOMDocument saveHTML incorrectly encoding href attributes

AcidX

New Member
I am using DOMDocument to load some user contributed HTML blocks and then manipulate them. It appears (assuming I am doing everything correctly) that DOMDocument is running the urls inside an href attribute through htmlentities. This is making my anchor tags which have ampersands in the query string come out incorrect.Example:\[code\]$html = <<<HTML<a href="http://foo.com?bar=baz&foo=bar">Foo</a>HTML;$dom = new DOMDocument;$dom->loadHTML($html);echo $dom->saveHTML();\[/code\]The output becomes(notice the & in the url was converted to \[code\]&\[/code\]):\[code\]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><body><a href="http://foo.com?bar=baz&foo=bar">Foo</a></body></html>\[/code\]Additionally, during the call to \[code\]$dom->loadHTML($html);\[/code\] the following warnings were output...\[quote\] Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 1\[/quote\]I have no idea what that means.Am I missing something?
 
Back
Top