我正在使用 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);
}
}
“第 41–111 页”中的破折号转换为
pp. 41–111
知道为什么以及如何修复它以获得 utf8 unicode 值吗?
先感谢您。
在我看来,数据是正确的,你只是显示不正确。
你是用UTF-8输出的吗?
à + 是一个经典的“将 UTF-8 编码的数据显示为非 UTF-8 编码的数据”。
例如。
如果您要输出到网络浏览器,请尝试使用元标记设置字符集。例如。
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
如果您需要以 UTF-8 以外的方式输出,则需要先转换为替代字符集。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)