我正在使用 DOMDocument 来提取一些段落。
这是我导入的初始 htm 文件的样子:
<html>
<head>
<title>Toxins</title>
</head>
<body>
<p class=8reference><span>1.</span><span>Sivonen, K.; Jones, G. Cyanobacterial Toxins. In <i>Toxic Cyanobacteria in Water. A Guide to Their Public Health Consequences, Monitoring and Management</i>; Chorus, I., Bartram, J., Eds.; E. and F.N. Spon: London, UK, 1999; pp. 41–111.</span></p>
</body>
</html>
当我在做:
$dom_input = new \DOMDocument("1.0","UTF-8");
$dom_input->encoding = "UTF-8";
$dom_input->formatOutput = true;
$dom_input->loadHTMLFile($manuscript->getUploadRootDir().$manuscript->getFileName());
$paragraphs = $dom_input->getElementsByTagName('p');
foreach ($paragraphs as $paragraph) {
if($paragraph->getAttribute('class') == "8reference") {
var_dump($paragraph->nodeValue);
}
}
“pp. 41–111”中的破折号被转换为
pp. 41–111
知道为什么以及如何修复它以获得 utf8 unicode 值吗?
先感谢您。