Skip to content

Instantly share code, notes, and snippets.

@nicastelo
Created February 12, 2015 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicastelo/2cc725c25b9b00287e62 to your computer and use it in GitHub Desktop.
Save nicastelo/2cc725c25b9b00287e62 to your computer and use it in GitHub Desktop.
<?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