我建立了这段代码:
$url_athlete = 'https://www.sports-reference.com/olympics/athletes/tr/giangiorgio-count-trissino-1.html';
$html3 = file_get_html($url_athlete,true);
$results = array();
foreach($html3->getElementsById('results') as $tag3){
foreach($tag3->getElementsByTagName('tr') as $tag4){
echo $tag4->plaintext . "\n";
}
}
感谢这段代码,如果我打印出获得此输出的tag4变量:
Games Age City Sport Event Team NOC Rank Medal
1900 Summer 22 Paris Equestrianism Mixed Long Jump Italy ITA 2 Silver
1900 Summer 22 Paris Equestrianism Mixed High Jump Italy ITA 1T Gold
1900 Summer 22 Paris Equestrianism Mixed High Jump Italy ITA 4
好吧,我尝试过多种方式但没有结果,我想从tag4获取这些值并将它们分配给变量,即:
$year --> 1900
$season --> Summer
$Sport --> Equestrianism
$gender -> Mixed
$event --> Long Jump
$rank --> 2
$medal --> silver
之后我会将这些值插入表中。 然后第二行:
$year --> 1900
$season --> Summer
$Sport --> Equestrianism
$gender -> Mixed
$event --> High Jump
$rank --> 1T
$medal --> gold
然后插入,依此类推最后一行。 我该怎么办?