用PHP提取纯HTML简单的HTML DOM解析器
问题描述:
你可以用“php简单的html dom”取一段HTML而不仅仅是内容吗?用PHP提取纯HTML简单的HTML DOM解析器
我与特里:
foreach ($html->find('div.info-bar') as $infop) {
$info = $infop->plaintext;
}
不幸的是,输出是:
24级奖杯4201铜奖2725银1057黄金341白金78 等级24 66 66%
虽然我想提取纯粹的HTML ..
这是我的代码:
include('simple_html_dom.php');
$html = file_get_html('https://my.playstation.com/obaidmiz04');
foreach ($html->find('div.info-bar') as $infop) {
$info = $infop->plaintext;
}
echo $info;
答
$escapedHtmlChars = "";
$htmlElements = "";
$html = file_get_html('https://my.playstation.com/obaidmiz04');
foreach ($html->find('div.info-bar') as $infop) {
//You can see html characters in text
//This shows you html codes, not for using
$escapedHtmlChars .= htmlspecialchars($infop);
//You can see html elements
$htmlElements .= $infop;
//You can see only text in selected element
$plainText .= $infop->plaintext;
}
echo $plainText;
echo "<br /> <br />";
echo $escapedHtmlChars;
echo "<br /> <br />";
echo $htmlElements;
明文方法只返回选定元素的文本。
你可能想将字符串添加到'$ info'变量中,而不是覆盖它。所以在循环中使用'。='而不是'='。 – ferdynator
我试过了,但继续只打印文本而不是html ... – Xanger