Ver Mensaje Individual
  #20 (permalink)  
Antiguo 08/10/2011, 19:11
Avatar de andresdzphp
andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 8 meses
Puntos: 793
Respuesta: problema con api y xml no logro lo que busco

Bueno necesitas usar $_GET y ya no necesitarías más. Como dato adicional te agregue para que detecte si es valido o no el usuario...


Código PHP:
Ver original
  1. class Obj2xml
  2. {
  3.     public $xmlResult;
  4.    
  5.     function __construct($rootNode) {
  6.         $this->xmlResult = new SimpleXMLElement("<$rootNode></$rootNode>");
  7.     }
  8.    
  9.     private function iteratechildren($object, $xml) {
  10.         foreach ($object as $name => $value) {
  11.             if (is_string($value) || is_numeric($value)) {
  12.                 $xml->$name = $value;
  13.             } else {
  14.                 $xml->$name = null;
  15.                 $this->iteratechildren($value, $xml->$name);
  16.             }
  17.         }
  18.     }
  19.    
  20.     function toXml($object) {
  21.         $this->iteratechildren($object, $this->xmlResult);
  22.         return $this->xmlResult->asXML();
  23.     }
  24. }
  25.  
  26. require ('xbox.php');
  27.  
  28. if (!empty($_GET['usuario'])) {
  29.    
  30.     $usuario = $_GET['usuario'];
  31.    
  32.     $xbox = new XboxGamercard();
  33.     $xbox->setGamertag($usuario);
  34.     $xbox->setRegion('en-GB');
  35.     $data = @$xbox->fetchData();
  36.    
  37.     if ($data->is_valid != 0) {
  38.         $converter = new Obj2xml("API");
  39.         header("Content-Type:text/xml");
  40.         echo $converter->toXml($data);
  41.     } else {
  42.         echo 'Usuario no es valido';
  43.     }
  44. }

tu URL seria http://ejemplo.com?usuario=malatos
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP