0

Try this query:

http://www.dictionaryapi.com/api/v1/references/collegiate/xml/gobabola?key=135a6187-af83-4e85-85c1-1a28db11d5da

How do I simply read in the suggestions as variables? I can't seem to find anything that explains this.

the5thace
  • 51
  • 2
  • 8
  • By using [SimpleXML](http://php.net/manual/en/book.simplexml.php) or [DOMDocument](http://php.net/manual/en/class.domdocument.php). [Here is a good explanation](http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of-xml-file) – Michael Berkowski Jul 16 '13 at 10:59
  • And there are [several examples here](http://stackoverflow.com/search?q=read+xml+with+php) which cover the process of loading the file via `simplexml_load_file()` – Michael Berkowski Jul 16 '13 at 11:02

1 Answers1

1

You can use SimpleXmlIterator. That's really easy to use and you will be able to perform a foreach on the object you will get.

Library source

For example with file_get_contents or replace with curl if you prefer:

    $feed = new SimpleXmlIterator(file_get_contents('http://www.dictionaryapi.com/api/v1/references/collegiate/xml/gobabola?key=135a6187-af83-4e85-85c1-1a28db11d5da'));
    foreach ($feed->suggestion as $suggestion) {
        echo $value;
      }
David Level
  • 353
  • 2
  • 16