<?php
$url = "https://my-test.illinoisstate.edu/service/it363/directory";
$params = array(
"uid" => "833330103"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$result = curl_exec($ch);
curl_close($ch);
header("content-type: text/xml");
echo $result;
$xml = simplexml_load_string($result);
echo $xml['uid'];
PHP parsing XML from Web Service
Page 1 of 14 Replies - 442 Views - Last Post: 28 November 2012 - 11:41 PM
#1
PHP parsing XML from Web Service
Posted 26 November 2012 - 10:37 PM
First of all, I have tried researching with Google to no success. I have a web service that is returning XML, but I can not find a way to parse it that works. I have tried simplexml in many different ways and it's just not working. I am unexperienced with PHP and could use some help. I am creating an website that uses this web service or one just like it to get its information. I need to be able to pick out certain data from the XML and use it in my code.
Replies To: PHP parsing XML from Web Service
#2
Re: PHP parsing XML from Web Service
Posted 26 November 2012 - 11:53 PM
I would expect line #24 not to work. afaik, SimpleXMLElement does not implement the ArrayAccess interface. so I’d go for $xml->uid.
#3
Re: PHP parsing XML from Web Service
Posted 27 November 2012 - 01:12 AM
#4
Re: PHP parsing XML from Web Service
Posted 27 November 2012 - 01:25 AM
then your only choice is to make a dump: var_dump($xml);
#5
Re: PHP parsing XML from Web Service
Posted 28 November 2012 - 11:41 PM
If in doubt, always var_dump() variable to see what's actually inside. Guessing is no good, really.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote





|