$DOM = new DOMDocument();
@$DOM->loadHTML($html);
$finder = new DomXPath($DOM);
$classname = 'winning-numbers';
$nodes = $finder->query("//*[contains(@class, '$classname')]");
foreach ($nodes as $node) {
echo "<p>","<b>11 AM Draw:","\n",$node->nodeValue,"</b>","</p>";
// I add paragraph and bold tags on the echo output but this site recognize the tags.
}
我差不多完成了它。 问题是我想像这样输出
11 AM Draw: 111(just an example value)
4 PM Draw: 222(just an example value)
9 PM Draw: 333(just an example value)
但我得到了这个
11 AM Draw: 2-2-0
11 AM Draw: 7-7-2
11 AM Draw: 1-6-1
答案 0 :(得分:2)
使用str_replace
功能查找并替换字符串中的字符:
$time = array('11 AM', '4 PM', '9 PM');
$i = 0;
foreach ($nodes as $node) {
echo "<p><b>".$time[$i]." : ".str_replace("-","",$node->nodeValue)."</b></p>";
$i++;
}