How to find a specific value with Simple HTML DOM Parser?

I need to get only values for “since”, instead I get all values with the same name of class.

$html = file_get_html("http://www.transfermarkt.co.uk/scottish-premiership/verletztespieler/wettbewerb/SC1/plus/1");
foreach ($html->find('.zentriert') as $element){
    echo $element->plaintext ."\n";
}

Result after running the code

Club Age Nation since until

28

Dec 27, 2016 Feb 24, 2017

33

Dec 24, 2016 Feb 28, 2017

25

Jan 31, 2017 Feb 28, 2017

19


I need to retrieve only the data from the column I selected.


I used this code to get the names for players i want to do the same for the column SINCE

foreach ($html->find('.hauptlink') as $element) {
    $player_name = trim($element->plaintext);
    echo $player_name ."\n";
}

At the end what i need to achieve is to get the player name, nation, injury, since and until values for earch row.

You’re trying to do it the hard way. If it was me, I’d…

  1. pull the table into a DOM structure.
  2. then pull the thead structure to find the appropriate column indexes
  3. THEN I’d parse the TBODY structure to get the appropriate columns based on step 2.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.