如何将两个节点放在同一个循环中?
how to put both nodes in same cycle?
这是我用的:
libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile("https://www.gismeteo.ru/city/weekly/4230/");
$xpath = new DomXPath($dom);
$weekday= $xpath->query('//*[@id="weather-weekly"]//div[@class="weekday"]');
$date= $xpath->query('//*[@id="weather-weekly"]//div[@class="s_date"]');
foreach ($weekday as $node4){
foreach ($date as $node3){
echo $node4->nodeValue,$node3->nodeValue,"<br>";}}
$node4->nodeValue
打印出星期几 sun, mon, tue...
和 $node3->nodeValue
打印出月份中的第几天,我如何让它像这样在同一列中打印所有内容 sat 23.07, sun 24.08...
?谢谢。
$xpath = new DomXPath($dom);
$days = $xpath->query('//*[@id="weather-weekly"]//div[@class="wbshort"]');
foreach ($days as $day) {
// find weekday and date under day
$weekday= $xpath->query('.//div[@class="weekday"]', $day);
$date= $xpath->query('.//div[@class="s_date"]', $day);
echo $weekday->item(0)->nodeValue . " " . $date->item(0)->nodeValue;
}
这是我用的:
libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile("https://www.gismeteo.ru/city/weekly/4230/");
$xpath = new DomXPath($dom);
$weekday= $xpath->query('//*[@id="weather-weekly"]//div[@class="weekday"]');
$date= $xpath->query('//*[@id="weather-weekly"]//div[@class="s_date"]');
foreach ($weekday as $node4){
foreach ($date as $node3){
echo $node4->nodeValue,$node3->nodeValue,"<br>";}}
$node4->nodeValue
打印出星期几 sun, mon, tue...
和 $node3->nodeValue
打印出月份中的第几天,我如何让它像这样在同一列中打印所有内容 sat 23.07, sun 24.08...
?谢谢。
$xpath = new DomXPath($dom);
$days = $xpath->query('//*[@id="weather-weekly"]//div[@class="wbshort"]');
foreach ($days as $day) {
// find weekday and date under day
$weekday= $xpath->query('.//div[@class="weekday"]', $day);
$date= $xpath->query('.//div[@class="s_date"]', $day);
echo $weekday->item(0)->nodeValue . " " . $date->item(0)->nodeValue;
}