Skip to content

Instantly share code, notes, and snippets.

@nccdr
Last active November 7, 2019 22:07
Show Gist options
  • Save nccdr/1f8784c705111ad446e61ff03e192511 to your computer and use it in GitHub Desktop.
Save nccdr/1f8784c705111ad446e61ff03e192511 to your computer and use it in GitHub Desktop.
HTML table to Array
<?php
/**
*
* HTML Table parser
* github.com/nicecodergit
*
*/
function getArrayFromFile( $link )
{
$finalArray = [];
$ch = curl_init( $link );
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$file = curl_exec( $ch );
curl_close( $ch );
$dom = new DOMDocument();
@$xls = $dom->loadHTML($file);
$tables = $dom->getElementsByTagName("tbody");
for($k = 0; $k < $tables->length; $k++){
$table = $tables->item($i);
$table = $table->getElementsByTagName("tr");
for( $i = 0; $i < $table->length; $i++ )
{
$row = $table->item($i);
$columns = $row->getElementsByTagName("td");
for( $j = 1; $j < $columns->length-1; $j++ )
{
$value = $columns->item($j)->nodeValue;
if($j == 1 or preg_match("#[0-9]+\/[0-9]+\:[0-9]+#", $value)){
if(@!array_search($value, $finalArray[$k]["time"])){
$finalArray[$k]["time"][] = $value;
}
}else{
if(!$value == "Леон Футбол"){
$finalArray[$k][$i][] = $value;
}
}
}
}
}
return $finalArray;
}
$array = getArrayFromFile("https://ru.surebet.com/surebets");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment