将 utf-8 字符与 QueryPath 和 HTML 一起使用


Using utf-8 chars with QueryPath and HTML

我正在尝试使用QueryPath在PHP中操作HTML。在将某些 utf-8 字符与 ->html() 和 ->text() 方法一起使用之前,它可以正常工作。即使使用 html 字符也不能解决问题。

有问题的例子:

$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

我尝试了多种组合,但没有成功。

如果我注释掉第二行并取消注释第三行,我会收到以下警告:警告:

DOMDocumentFragment::appendXML(): 实体:第 1 行:解析器错误:实体 'aring' 未在第 1208 行的 D:''Inetpub''wwwroot''QueryPath-2.1.2-minimal''QueryPath.php 中定义 警告: DOMDocumentFragment::appendXML(): å in D:''Inetpub''wwwroot''QueryPath-2.1.2-minimal''QueryPath.php 在第 1208 行 警告: DOMDocumentFragment::appendXML(): ^ in D:''Inetpub''wwwroot''QueryPath-2.1.2-minimal''QueryPath.php 在第 1208 行

我注意到我必须将 php 文件的编码设置为 utf-8 并且它起作用了。但是,我仍然没有找到使用 html 字符的方法。