-
-
Save victorcosta12/5101377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ============ OBTER DADOS DA URL: http://www.mar.mil.br/dhn/chm/tabuas/ ============ | |
$dom = new domDocument; | |
$dom->loadHTML($html); | |
$dom->preserveWhiteSpace = false; | |
$tables = $dom->getElementsByTagName('table'); | |
$rows = $tables->item(0)->getElementsByTagName('tr'); | |
$arMare = array(); | |
$gravando = 0; | |
foreach ($rows as $row) { | |
$cols = $row->getElementsByTagName('td'); | |
$dia = substr(trim($cols->item(1)->nodeValue),-10); | |
$hora = trim($cols->item(2)->nodeValue); | |
$mare = trim($cols->item(3)->nodeValue); | |
if($gravando == 1 && !empty($dia)) | |
break; | |
if($dados['data'] == $dia || $gravando == 1) { | |
if(!empty($hora) && !empty($mare)) { | |
array_push($arMare, array('dia' => $dia, | |
'hora' => $hora, | |
'mare' => $mare)); | |
} | |
$gravando = 1; | |
} | |
} | |
$dadosmare = "["; | |
foreach($arMare AS $v) { | |
$dadosmare .= "['".$v['hora']."','".$v['mare']."'],"; | |
} | |
// Retirar última vírgula para compatibilidade com IE | |
$dadosmare = substr($dadosmare, 0, -1); | |
$dadosmare .= "]"; | |
$dados['mare'] = $dadosmare; | |
json_encode($dados) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment