Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

using php to get information from XML web services in an API server

Posted on 2006-10-29
2
Medium Priority
?
288 Views
Last Modified: 2006-11-18
how can i get information from XML web services in an API server using php

0
Comment
Question by:intazaar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
soapergem earned 2000 total points
ID: 17832088
If you're familiar with SOAP (Simple Object Access Protocol), it is supported in PHP5. I'm not really familiar with it myself, but I know it goes hand-in-hand with many web services.
http://www.php.net/soap

Also in PHP5, there are some functions to parse the XML response using the SimpleXML extension.
http://www.php.net/simplexml

I'm still using PHP4, myself, so what I generally do is to use the file_get_contents() function, which accepts a URL parameter, to retrieve the API responses. I usually just write regular expressions to grab the data I'm interested in, but there's also a built-in XML parser, but it is a little different from the one in PHP5. Assuming you have the XML response in $data, you could execute code like this to parse it:

    $data = file_get_contents('http://www.web.services.com/service?api_key=123456');
   
    $parser = xml_parser_create('UTF-8');
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $vals, $index);
    xml_parser_free($parser);

http://www.php.net/xml-parser-create
http://www.php.net/file-get-contents
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 17835804
In php4 you can also use the xml_unserialize by Keith Devens. It converts an xml message into an array and vice versa.

-r-
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question