Created
February 12, 2015 20:18
-
-
Save nicastelo/2cc725c25b9b00287e62 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 | |
//Le indico que va a mostrar un json | |
header("Content-Type: text/json; charset=iso-8859-1"); | |
//quito los errores por las etiquetas html5 | |
libxml_use_internal_errors(true); | |
//Guardo la url pasada por get | |
$url = $_GET["url"]; | |
if(preg_match('#^http://historiascorrientes.enlatino.net.*#s', trim($url))){ | |
//Funciona | |
} else{ | |
$data = array('msg' => 'bad url'); | |
echo json_encode($data); | |
return false; | |
} | |
//Tomo el código y lo meto en una variable | |
$fo= fopen($url,"r") or die ("No se encuentra la pagina."); | |
while (!feof($fo)) { | |
$cadena .= fgets($fo, 4096); | |
} | |
fclose ($fo); | |
//Cargo la cadena como documento DOM | |
$doc = new DOMDocument(); | |
$doc->loadHTML($cadena); | |
$title = $doc->getElementById('titulo-serie')->nodeValue; | |
$episodio = $doc->getElementById('copiame')->nodeValue; | |
$url1 = $doc->getElementById('tab-1')->getElementsByTagName('iframe')->item(0)->getAttribute('src'); | |
$url2 = $doc->getElementById('tab-2')->getElementsByTagName('iframe')->item(0)->getAttribute('src'); | |
//Guardo todo en un array | |
$data = array('title' => $title, 'episodio' => $episodio, 'url1' => $url1, 'url2' => $url2, 'msg' => 'success'); | |
//imprimo el array como json | |
echo json_encode($data); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment