Comunidad de diseño web y desarrollo en internet online

Interpretar contenido de variable

Citar            
MensajeEscrito el 29 Dic 2005 01:10 pm
Hola chicos, tengo un problemilla y necesito vuestra ayuda,

Os cuento:

recibo una variable, "$respuesta", de otro servidor con el que realizo una serie de operaciones.

el contenido de esta variable es una cadena como esta:

HTTP/1.1 200 OK
Date: Mon, 26 Dec 2005 12:30:32 GMT
Server: Microsoft-IIS/5.0
pragma: no-cache
cache-control: no-store
Content-Length: 116
Content-Type: text/html; charset=ISO-8859-1
Expires: Mon, 26 Dec 2005 12:42:58 GMT
Set-Cookie: ASPSESSIONIDAQCBQTBC=COFFBMNAGFICPGBCFANIOHAG; path=/
Cache-control: private
Connection: close


<html>
<body>
<DATOS><ESTADO>1</ESTADO><ERROR></ERROR><CODOP>000001-000002</CODOP></DATOS>
</body>
</html>

mi problema es que necesito extraer como variables los valores que aparecen al final de la respuesta, es decir : ESTADO, ERROR y CODOP, que parecen ser algo parecido a un xml, para guardarlos en una base de datos.

Gracias de antemano,

Flip

Por flip_sp

18 de clabLevel



 

msie
Citar            
MensajeEscrito el 29 Dic 2005 05:33 pm
no es algo optimo pero te servira de ayuda

Código :

<?php
$respuesta="HTTP/1.1 200 OK
Date: Mon, 26 Dec 2005 12:30:32 GMT
Server: Microsoft-IIS/5.0
pragma: no-cache
cache-control: no-store
Content-Length: 116
Content-Type: text/html; charset=ISO-8859-1
Expires: Mon, 26 Dec 2005 12:42:58 GMT
Set-Cookie: ASPSESSIONIDAQCBQTBC=COFFBMNAGFICPGBCFANIOHAG; path=/
Cache-control: private
Connection: close


<html>
<body>
<DATOS><ESTADO>1</ESTADO><ERROR></ERROR><CODOP>000001-000002</CODOP></DATOS>
</body>
</html>";
$string=explode("<html>",$respuesta);
//$string = ereg_replace("\n","<br>",$string);
$string[1] = preg_replace( "/<ESTADO>(.*?)<\/ESTADO>/","\\1%", $string[1] );
$string[1] = preg_replace( "/<ERROR>(.*?)<\/ERROR>/","\\1%", $string[1] );
$string[1] = preg_replace( "/<CODOP>(.*?)<\/CODOP>/","\\1", $string[1] );
echo "$string[1] <br/>";
$varibles=explode("%",$string[1]);

echo "estado=$varibles[0] y error=$varibles[1] y codop=$varibles[2]";

?>

Por alexisquero2

37 de clabLevel



Genero:Masculino  

venezuela

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.