CURL POSTFIELDS包含“&";性格


CURL POSTFIELDS to contain "&" character

我使用CURL方法通过网关发送短信。但是,如果我在我的消息文本区域中包含这个字符"&",它将只在这个字符之前发送消息。

那么我该如何修复它以正常发送包含此字符的消息呢。

这是我的代码:

$from = "Gateway_username"; // SMS username
$token = "Gateway_password"; // SMS password
$option = $_REQUEST["option"];
$text = $_REQUEST["BulkSMS1__messageTextBox"];
if ($text == "") { } else {
    $url = "http://awaljawaly.awalservices.com.sa:8001/Send.aspx";
    $postfields = array ("REQUESTTYPE" => "SMSSubmitReq",
    "Username" => "$from", "Password" => "$token", "MOBILENO" => "$d_mobile", "MESSAGE" => "$text");
    if (!$curld = curl_init()) {
    echo "Could not initialize cURL session.";
    exit;
    }
    curl_setopt($curld, CURLOPT_POST, true);
    curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);
    curl_setopt($curld, CURLOPT_URL, $url);
    curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($curld);
    curl_close ($curld);
    preg_match("/(.*)/",$output, $out);
}

这是一条示例消息:

我们的地址:H&R中心。

提前谢谢。

我用这个来解决我的问题:

$text = str_replace('&', '%26', $_REQUEST["BulkSMS1__messageTextBox"]);

您需要对字符进行编码:

http://www.clockworksms.com/blog/the-gsm-character-set/

有了这个,尝试使用:

utf8_encode()

原因是你是为移动设备编码,而不是为网站编码,所以与utf8编码相比,使用url编码将不起作用。

请参阅urlencode()->http://php.net/manual/en/function.urlencode.php

<?php
$text = urlencode($_REQUEST["BulkSMS1__messageTextBox"]);
?>

我已经用它来解决我的问题:

$text = str_replace('&', '%26', $_REQUEST["BulkSMS1__messageTextBox"]);