将 HTTP 响应从 curl HTTP 检索到变量中


Retrieving HTTP response from curl HTTP into variables

我正在使用php中的cURL通过SMSGlobals HTTP API提交,并在成功发送时响应此内容。

确定: 0;已发送排队消息 ID: 941596d028699601 SMSGlobalMsgID:6764842339385521

我的网址代码

//open CURL connection
$ch = curl_init();
//set url, variables and post
curl_setopt($ch,CURLOPT_URL, $httpsend);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);

我的问题是我需要提取初始 OK(如果有错误,这是一个错误)。与消息 ID 和 SMSGlobalMsgID 一起放入变量中,以便我可以使用它们进行确认。我似乎无法让它工作。

这就是我最终所做的。希望这对任何有类似问题的人有所帮助。

//open CURL connection
$ch = curl_init();
//set url, variables and post
curl_setopt($ch,CURLOPT_URL, $httpsend);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
//Break out response into variables separated by :
list($var1, $var2, $var3, $var4) = explode(":", $result)