PHP submits XML in POST mode, obtains XML, and parses XML detailed explanation and examples_php implementation

墨辰丷
Release: 2023-03-28 15:52:02
Original
1892 people have browsed it

This article mainly introduces PHP to submit XML in POST method, obtain XML, parse XML detailed explanation and related examples. Friends in need can refer to the following

PHP submit XML in POST method, Get XML, and finally parse XML

Submit XML in POST

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

//$data = array(&#39;name&#39; => &#39;Dennis&#39;, &#39;surname&#39; => &#39;Pallett&#39;);

// 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);
Copy after login

Get POST to XML , and parse

handle_form.php

$file_in = file_get_contents("php://input"); //接收post数据

$xml = simplexml_load_string($file_in);//转换post数据为simplexml对象

foreach($xml->children() as $child)  //遍历所有节点数据
{

echo $child->getName() . ": " . $child . "<br />"; //打印节点名称和节点值

//if($child->getName()=="from")  //捡取要操作的节点
//{
//echo "i say ". ": get you!" . "<br />"; //操作节点数据
//}
}

exit;
Copy after login

. The above is the entire content of this article. I hope it will be useful for everyone’s learning. helped.


Related recommendations:

php How to encapsulate classes in mysql database

phpHow to encapsulate the mongodb database

PHP JavaScript implements cookie reading, writing and interactive operation methods in detail

The above is the detailed content of PHP submits XML in POST mode, obtains XML, and parses XML detailed explanation and examples_php implementation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template