这里有新鲜出炉的 PHP 设计模式,程序狗速度看过来!
PHP(外文名: Hypertext Preprocessor,中文名:"超文本预处理器")是一种通用开源脚本语言。语法吸收了 C 语言、Java 和 Perl 的特点,入门门槛较低,易于学习,使用广泛,主要适用于 web 开发领域。PHP 的文件后缀名为 php。
这篇文章主要介绍了 PHP 以 POST 方式提交 XML、获取 XML,解析 XML 详解及实例的相关资料, 需要的朋友可以参考下
PHP 以 POST 方式提交 XML、获取 XML,最后解析 XML
以 POST 方式提交 XML
- // 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);
获取 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;
来源: http://www.phperz.com/article/17/0809/341678.html