PHP 以POST方式提交XML、擷取XML,解析XML詳解及執行個體_php實

來源:互聯網
上載者:User
這篇文章主要介紹了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 optionscurl_setopt($ch, CURLOPT_URL,"http://localhost/handle_form.php");curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);// grab URL, and printcurl_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;

以上就是本文的全部內容,希望對大家的學習有所協助。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.