0

I am receiving XML POSTED via curl, and can successfully write the posted XML to a file, so I know that its being posted successfully.

I really need to access the posted XML and create an array as soon as it is received, so I can set up variables and prepare the posted XML for a database Insert.

Can anyone show an example of how I would access the XML, received as:

$postXML = trim(file_get_contents('php://input'));

Which is:

<?xml version="1.0" encoding="UTF-8" ?>
<data>
    <first_name>Larry</first_name>
    <last_name>Jones</last_name>
    <url>www.somewhere.com</url>
</data>

I need to access <first_name>, <last_name> and <url> and create as variables for processing and DB inserts.

Any help is very much appreciated!

1 Answer 1

1

Use simplexml
Load the XML string with:

$xml = simplexml_load_string($postXML); 

Then access the data you want:

$first_name = (string)$xml->first_name;
$last_name = (string)$xml->last_name;
$url = (string)$xml->url;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That worked perfectly .. I'll read up on simplexml.

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.