PHP submits XML in post, obtains XML, parses XML and Example _php instance

Source: Internet
Author: User

PHP submits XML as post, obtains XML, and finally parses XML

Submit XML as Post

Do a POST
$data = "<?xml version= ' 1.0 ' encoding= ' UTF-8 '?>
<TypeRsp>
<connect_id>1 </CONNECT_ID>
<MO_MESSAGE_ID>2</MO_MESSAGE_ID>
</TypeRsp> ";

$data = Array (' name ' => ' Dennis ', ' surname ' => ' Pallett ');

Create a new curl resource
$ch = Curl_init ();
Set URL and other appropriate options
curl_setopt ($ch, Curlopt_url, "http://localhost/handle_form.php");
curl_setopt ($ch, Curlopt_post, true);
curl_setopt ($ch, Curlopt_postfields, $data);
Grab URL, and print
curl_exec ($ch);

Get post to XML and parse

handle_form.php


$file _in = file_get_contents ("Php://input"); Receive post data

$xml = simplexml_load_string ($file _in);//convert post data to SimpleXML object

foreach ($xml->children () as $ Child)  //Traverse all node data
{

echo $child->getname (). ": " . $child. "<br/>"; Print node name and node value

//if ($child->getname () = "from")  //Pick up node to operate
//{
//echo "I Say". ": Get you!". "<br/>"; Operation node data
//}
}

exit;

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.