2

Is there a way to read off from an [external] xml (an xml file from a different website) using PHP? I know there's a way to read XML using JavaScript, but only if they are both in the same root.

Could you provide an example on how to source the xml file, then read the following:

<parent>
    <child>
        <grandchild>Example Text 1</grandchild>
    </child>

    <child>
        <grandchild>Example Text 2</grandchild>
    </child>
</parent>

Thanks!

2 Answers 2

6

The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.

https://www.php.net/manual/en/simplexml.examples-basic.php

Sign up to request clarification or add additional context in comments.

3 Comments

+1 extension: see the load function. I personally use this approach to pull from my twitter account.
I recommend SimpleXML extension, too. I'm also using it for some twitter stuff.
This is really good, but what's the code to read it off of a foreign XML file? What I need to do is display results from an XML file that's on a different page (kinda like loading data from twitter). Thanks a lot guys.
1

Use fopen to read files over http and take your pick of the approaches to read XML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.