【问题标题】:Simple PHP Dom Parser to find HTML ID with symbols使用符号查找 HTML ID 的简单 PHP Dom 解析器
【发布时间】:2015-12-08 14:08:53
【问题描述】:

我遇到了 PHP 简单 HTML dom 解析器的问题。 我找到一个带有 ® 符号的 html ID,但 API 无法识别(该类存在于 html 文件中)。

?>
header('Content-Type: text/html; charset=UTF-8');
require 'simple_html_dom.php';
$html = file_get_html('http://ark.intel.com/products/88194/Intel-Core-i7-6500U-Processor-4M-Cache-up-to-3_10-GHz');
//There is the problem on the ® symbol.
foreach($html->find('div#infosectionintel®platformprotectiontechnology-scrollpane') as $protection) {
$item8['osguardxx']     = $protection->find('tr#OSGuardTechVersion td.rc', 0)->plaintext;
$item8['txtxxxxxx']     = $protection->find('tr#TXT td.rc', 0)->plaintext;
$item8['exedisbit']     = $protection->find('tr#ExecuteDisable td.rc', 0)->plaintext;
$protections[] = $item8;
}
print_r($protections);
?>

我已经用其他没有符号的 div# 进行了测试,效果很好!! 谢谢你的帮助!

【问题讨论】:

  • 你确定源中有®符号吗?因为如果您回显它并从那里获取 id,浏览器可以将 &reg 设为该符号!

标签: javascript php html html-parsing


【解决方案1】:

您可以使用chr($ascii)(将 ascii 替换为 ® 的 ascii 代码),也可以使用如下通配符:

foreach($html->find('div[id*=infosectionintel]', 0) as $protection) {

它会查找名称中包含 infosectionintel 的任何 div id。

【讨论】:

  • 很高兴我能帮助塔里克 :)
猜你喜欢
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
  • 2019-12-18
  • 2012-01-17
  • 1970-01-01
  • 1970-01-01
  • 2020-03-02
相关资源
最近更新 更多