We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,627 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

CURL XML string to array

Hi There,

I have a usage problem with CURL output.

I have a web services and I use CURL to get the data, However this web services set up as XML output and I want to convert it to array to use the result in the web form.

My CURL is

$cnum="$mn";
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://xxx.pl');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS ,"cnum=$cnum");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$file_contents = htmlspecialchars(curl_exec($ch));
curl_close($ch);
echo"<pre>";

echo $file_contents;

I have the output;

<?xml version="1.0" encoding="utf-8"?>
<volunteer_roles>
	<role code="BNA" name="Branch Advertising ">N</role>
	<role code="BEC" name="Branch Caesarean Contact">N</role>
	<role code="BC" name="Branch Co-ordinator / Chair">N</role>
	<role code="BW" name="Branch Web Co-ordinator">N</role>
	<branch>515</branch>
</volunteer_roles>

And I want to use this result in a form with check boxes..

Does anybody have an idea?

Thank You

2
Contributors
2
Replies
1 Day
Discussion Span
2 Years Ago
Last Updated
3
Views
Question
Answered
kadriirdak
Light Poster
33 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

For small xml files, SimpleXML is nice, but in php, there are quite a few ways to parse xml, as you can read here.

twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 102
Skill Endorsements: 5

Thanks for the post - Problem sorted!

kadriirdak
Light Poster
33 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 2 Years Ago by twiss

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0559 seconds using 2.65MB