Home> php教程> PHP开发> body text

PHP submits XML via POST, obtains XML, and parses XML details and examples

高洛峰
Release: 2017-01-06 15:12:48
Original
1438 people have browsed it

PHP Submit XML in POST mode, obtain XML, and finally parse XML

Submit XML in POST mode

// Do a POST $data="  1 2 "; //$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);
Copy after login

Get POST to XML, and parse it

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 . "
"; //打印节点名称和节点值 //if($child->getName()=="from") //捡取要操作的节点 //{ //echo "i say ". ": get you!" . "
"; //操作节点数据 //} } exit;
Copy after login

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

For more PHP articles about submitting XML via POST, obtaining XML, parsing XML details and examples, please pay attention to the PHP Chinese website!

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 Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!