Question

I'm trying to use QueryPath to manipulate HTML in PHP. It works fine until certain utf-8 characters are used along with the ->html() and ->text() methods. Even using html-characters doesn't solve the problem.

Problematic example:

$html = "<html><body id='a'>test</body></html>";
$html = qp($html, "#a" )->text("å")->top()->html(); // results in disappearing html code
//$html = qp($html, "#a" )->html("&aring;")->top()->html(); // generates warnings
echo $html

I have tried a multitude of combinations without success.

If I comment out the second line and uncomment the third, I get these warnings: Warning: DOMDocumentFragment::appendXML(): Entity: line 1: parser error : Entity 'aring' not defined in D:\Inetpub\wwwroot\QueryPath-2.1.2-minimal\QueryPath.php on line 1208 Warning: DOMDocumentFragment::appendXML(): å in D:\Inetpub\wwwroot\QueryPath-2.1.2-minimal\QueryPath.php on line 1208 Warning: DOMDocumentFragment::appendXML(): ^ in D:\Inetpub\wwwroot\QueryPath-2.1.2-minimal\QueryPath.php on line 1208

Was it helpful?

Solution

I noticed that I had to set the encoding of the php file to utf-8 and it worked. However, I still have not found a way to use html characters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top