socket output xml

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hope14
Forum Newbie
Posts: 1
Joined: Sun May 18, 2014 8:25 am

socket output xml

Post 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;
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: socket output xml

Post 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
Post Reply