Solved

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

Posted on 2006-10-29
2
280 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
2 Comments
 
LVL 6

Accepted Solution

by:
soapergem earned 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now