There is a table on the website Goal.com that I have attached to this question. I want to know how to store the strings in the column Player Name into a variable or database somehow.
The reason for this is because I have a variable in my code called $player
. This variable stores a different string every 24 hours and is printed onto my site. This is done by using a custom made function.
I want to code that if '$player' is equal to any string in the column 'Player Name' from goal.com
, to re-run the function so a different string is stored in variable and printed on my website.
TABLE : http://www.goal.com/en/scores/transfer-zone?ICID=TZ_DD1_VA
Answer
PHP Simple HTML DOM Parser can do the job for you. http://simplehtmldom.sourceforge.net/
Download simple_html_dom.php here; http://sourceforge.net/projects/simplehtmldom/files/simple_html_dom.php/download
Here is a full example.
include("simple_html_dom.php");
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile("http://www.goal.com/en/scores/transfer-zone?ICID=TZ_DD1_VA");
$xpath = new DOMXPath($doc);
$player_names = $xpath->query("//td[@class='player_name_col']");
foreach ($player_names as $player_name) {
echo $player_name->nodeValue . "
";
}
?>
No comments:
Post a Comment