网络编程 
首页 > 网络编程 > 浏览文章

PHP 以POST方式提交XML、获取XML,解析XML详解及实例

(编辑:jimmy 日期: 2024/5/20 浏览:3 次 )

PHP 以POST方式提交XML、获取XML,最后解析XML

以POST方式提交XML

// Do a POST
$data="<";

//$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);

获取POST来到XML,并解析

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;

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:php 解析xml 的四种方法详细介绍
下一篇:php 生成签名及验证签名详解
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网