Page 1 of 1

socket output xml

Posted: Mon May 19, 2014 5:51 am
by hope14
I pass a xml string in php socket and it returns me below xml as reply in $code; variable,

Code: Select all

<tel><header><responsetype>stock</responsetype></header><response><resultcode>60</resultcode><resultdescription>Invalid PIN</resultdescription><source>345</source><requestcts>19/05/2014 09:55:18 AM</requestcts><responsects>19/05/2014 09:55:18 AM</responsects><vendorcode>our</vendorcode></response></tel>
I want to print only value of

Code: Select all

<resultcode>60</resultcode>
which is 60.. pls guide how to extract that value from those tags

Code: Select all

$fp = fsockopen($host, $port ,$errno, $errstr, 30);
if (!$fp) {
  print 'COULD NOT CONNECT! <br />';
  echo "$errstr ($errno)<br />\n";
  die();
}
else

fputs ($fp, $xml."\n" );

#echo fread($fp, 1024);
$code=fread($fp, 1024);
print $code;

Re: socket output xml

Posted: Mon May 19, 2014 6:21 am
by pbs
Try this

Code: Select all

$xml = '<tel><header><responsetype>stock</responsetype></header><response><resultcode>60</resultcode><resultdescription>Invalid PIN</resultdescription><source>345</source><requestcts>19/05/2014 09:55:18 AM</requestcts><responsects>19/05/2014 09:55:18 AM</responsects><vendorcode>our</vendorcode></response></tel>';

$xmlobj = simplexml_load_string($xml);

echo $xmlobj->response->resultcode;
may this will help you