Symfony2 Crawler - 在XPATH中使用UTF-8

Mil*_*loš 2 php encoding xpath web-crawler symfony

我正在使用Symfony2 Crawler - Bundle来使用XPath.除编码外,一切正常.

我想使用UTF-8编码,而Crawler不知何故不使用它.我注意到因为它 被转换为 ,这是一个已知的问题:UTF-8编码问题

我的问题是:我怎么能强迫Symfony Crawler使用UTF-8编码?

这是我正在使用的代码:

$dom_input = new \DOMDocument("1.0","UTF-8");
$dom_input->encoding = "UTF-8";
$dom_input->formatOutput = true;

$dom_input->loadHTMLFile($myFile);

$crawler = new Crawler($dom_input); 
$paragraphs = $crawler->filterXPath('descendant-or-self::p');
Run Code Online (Sandbox Code Playgroud)

而现在,当我在做的时候

foreach($paragraphs as $paragraph) {
    var_dump($paragraph->nodeValue);
}
Run Code Online (Sandbox Code Playgroud)

 我的段落中有一个,我就得到了 .

非常感谢你提前.

Mil*_*loš 5

感谢@halfer,我找到了一个解决方法:

而不是使用

$crawler = new Crawler($dom_input);
Run Code Online (Sandbox Code Playgroud)

我用了:

$crawler = new Crawler();
$crawler->addHtmlContent(utf8_decode($dom_input->saveXML()));
Run Code Online (Sandbox Code Playgroud)