1. 读取POST 中的xml内容
$post_str = file_get_contents('php://input');
// 解析 XML 内容
$post_obj = simplexml_load_string($post_str, 'SimpleXMLElement', LIBXML_NOCDATA);
$from_username = $post_obj->FromUserName;
$to_username = $post_obj->ToUserName;
本文介绍了一种使用PHP从HTTP POST请求中读取并解析XML数据的方法。通过file_get_contents('php://input')获取原始XML字符串,并利用simplexml_load_string进行解析。
$post_str = file_get_contents('php://input');
// 解析 XML 内容
$post_obj = simplexml_load_string($post_str, 'SimpleXMLElement', LIBXML_NOCDATA);
$from_username = $post_obj->FromUserName;
$to_username = $post_obj->ToUserName;
被折叠的 条评论
为什么被折叠?