0

在这里,我正在尝试解析网页并获取内容.. http://www.reuters.com/finance/stocks/companyOfficers?symbol=AOS

这是我的代码,它与附加的示例结果一起进行解析。

现在,如果您在示例结果数组中看到,在描述字段中,一些细节的格式无效.. 例如。原始“描述”在网页中包含 (“Bemis”),但在解析结果中显示为 (├ó┬Ç┬£Bemis├ó┬Ç┬¥)(参见示例结果中的描述字段)。检查 url 的页面源并尝试搜索“Bemis”。可能是什么原因..如何解决它.? 我也试过

$html_source = str_replace('“','"',$html_source); 
$html_source = str_replace('”','"',$html_source); 

但无法正确处理.. 帮我修改代码,使其给出正确的解析结果。

4

1 回答 1

1

在代码的第 5 行之后添加它对我有用:

// First, replace UTF-8 characters.
$html_source = str_replace(
 array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
 array("'", "'", '"', '"', '-', '--', '...'),
 $html_source);

// Next, replace their Windows-1252 equivalents.
$html_source = str_replace(
 array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
 array("'", "'", '"', '"', '-', '--', '...'),
 $html_source);

感谢@Wolfe 在这个 SO 线程中:Devilish curly quotes

于 2012-08-26T18:29:46.280 回答