$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发布于 2015-06-09 14:35:48
使用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++;
}https://stackoverflow.com/questions/30735120
复制相似问题