PHP截取發(fā)動短信內(nèi)容的方法
772
2024-01-10
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數(shù)據(jù) $xml = simplexml_load_string($file_in);//轉(zhuǎn)換post數(shù)據(jù)為simplexml對象 foreach($xml->children() as $child) //遍歷所有節(jié)點(diǎn)數(shù)據(jù) { echo $child->getName() . ": " . $child . "<br />"; //打印節(jié)點(diǎn)名稱和節(jié)點(diǎn)值 //if($child->getName()=="from") //撿取要操作的節(jié)點(diǎn) //{ //echo "i say ". ": get you!" . "<br />"; //操作節(jié)點(diǎn)數(shù)據(jù) //} } exit;
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請用戶自負(fù)。本站信息來自網(wǎng)絡(luò)收集整理,版權(quán)爭議與本站無關(guān)。您必須在下載后的24個小時之內(nèi),從您的電腦或手機(jī)中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請支持正版,購買注冊,得到更好的正版服務(wù)。我們非常重視版權(quán)問題,如有侵權(quán)請郵件[admin@lxwl520.com]與我們聯(lián)系進(jìn)行刪除處理。敬請諒解!