Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/02/2015, 14:57
Avatar de Maganius
Maganius
 
Fecha de Ingreso: septiembre-2010
Mensajes: 310
Antigüedad: 13 años, 7 meses
Puntos: 10
Respuesta: Foreach y datos externos

Hola Pateketrueke, gracias por contestar

¿La web externa que consultas no dispone de un servicio web para el caso?
.- No tiene.

¿Cómo es que estás haciendo la petición a la web externa?
.- Pongo el script que utilizo, si necesitas que también te pase la url avisame que te envio un mp.

¿Has pensado en usar algún tipo de cache?
.- No puedo obtener la información como cache ya que los datos tienen que ser del momento, ya que además de verificar si el jugador existe también verifico si esta online.

Código PHP:
Ver original
  1. $html = file_get_contents($url);
  2.         $domd = $this->getDOMDocument($html);
  3.  
  4.         $domx = new \DOMXPath($domd);
  5.         $characters = $domx->query("//table[@class='TableContent'][1]//tr[position() > 1]");
  6.         $ret = array();
  7.  
  8.         foreach ($characters as $character) {
  9.             $name     = $domx->query("td[2]/a[@href]", $character)->item(0)->nodeValue;
  10.             $level    = $domx->query("td[4]", $character)->item(0)->nodeValue;
  11.             $vocation = $domx->query("td[3]", $character)->item(0)->nodeValue;
  12.             $online = $domx->query("td[6]", $character)->item(0)->nodeValue;
  13.  
  14.             $ret[] = array(
  15.                 "name"      =>  $name,
  16.                 "level"     =>  $level,
  17.                 "vocation"  =>  $vocation,
  18.                 "status"  =>  $online,
  19.             );
  20.         }
  21.  
  22.         return $ret;