Starting from this html page:
https://www.sports-reference.com/olympics/summer/1896/ATH/
I'm trying to get some information with the following script:
<?php
include_once ('C:\moduli\simple_html_dom.php');
function getTextBetweenTags($url, $tagname) {
$values = array();
$html = file_get_html($url);
foreach($html->find($tagname) as $tag) {
//echo $tag;
foreach($tag->find('a') as $a) {
//echo $a;
$values[] = $a->innertext. '<br>';
//echo $values[0];
}
print_r ($values);
unset($values);
}
//$result=explode("'s",$values[0]);
//array_pop($result);
//return $result;
}
$output = getTextBetweenTags('https://www.sports-reference.com/olympics/summer/1896/ATH/', 'tr class=""');
//echo '<pre>';
?>
What I get from the print_r array inside the loop is the following (only first rows):
Array ( ) Array ( [0] => Men's 100 metres
[1] => Tom Burke
[2] => Fritz Hofmann
[3] => Alajos Szokoly
[4] => Frank Lane
) Array ( [0] => Men's 400 metres
[1] => Tom Burke
[2] => Herbert Jamison
[3] => Charles Gmelin
) Array ( [0] => Men's 800 metres
[1] => Teddy Flack
[2] => Nándor Dáni
[3] => Dimitrios Golemis
) Array ( [0] => Men's 1,500 metres
[1] => Teddy Flack
[2] => Arthur C. Blake
[3] => Albin Lermusiaux
I'd like to store in separated variables (for example for 100 metres):
100 metres
Men
Tom Burke
USA --> (this one taken from "alt" attribute inside html)
Gold --> (static parameter for the first athlete)
then reset all and get for second loop
100 metres
Men
Fritz Hofmann
GER --> (this one taken from "alt" attribute inside html)
Silver --> (static parameter for the second athlete)
for the last two athletes, both won bronze so I'd like to get:
100 metres
Men
Alajos Szokoly
HUN --> (this one taken from "alt" attribute inside html)
Bronze --> (static parameter for the third athlete)
and
100 metres
Men
Frank Lane
USA --> (this one taken from "alt" attribute inside html)
Bronze --> (static parameter for the fourth athlete)
Last two athletes are recognizible because in html they are on the same row of td align="left" attribute.
How to get that? Thank you