我有一个PHP代码,它从数据库中获取输入值并将其存储在变量中,输入是一个固定的短信模板,无法更改。
所以我必须将它存储在变量中以向用户发送短信。
$sql = "Select * from `test` where `flag` = '0'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$n = $row['number'];
$m = $row['user'];
$p = $row['pass'];
$request =""; //initialise the request variable
$param['method']= "sendMessage";
$param['send_to'] = "$n";
$param['msg'] = "Dear Customer, Delighted to inform you about "MYZICOM app" India's first service app in security industry . Download now and get 24*7 Service and bills management assistance for your ZICOM MYCS security solutions & services with many more benefits. Your Unique Username: $m & Password: $p. For any queries /assistance pls call 1800-270-4567 (Currently available only for Android users)";
$param['userid'] = "XXXX";
$param['password'] = "XXXX";
$param['v'] = "1.1";
$param['msg_type'] = "TEXT"; //Can be "FLASHâ€/"UNICODE_TEXT" /â€BINARYâ€
$param['auth_scheme'] = "PLAIN";
//Have to URL encode the values
foreach($param as $key=>$val) {
$request.= $key."=".urlencode($val);
//we have to urlencode the values
$request.= "&";
//append the ampersand (&) sign after eachparameter/value pair
}
$request = substr($request, 0, strlen($request)-1);
//remove final (&) sign from the request
$url ="http://enterprise.smsgupshup.com/GatewayAPI/rest?".$request;
$ch = curl_init($url);
// $data = $ch;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
所以问题是我的短信中有一个固定的单引号和双引号逗号,我必须将它存储在一个变量中。 怎么解决?
答案 0 :(得分:1)
正如我在评论中所说,逃避“用反斜杠\即。
$param['msg'] = "Dear Customer, Delighted to inform you about \"MYZICOM app\" India's first service app in security industry . Download now and get 24*7 Service and bills management assistance for your ZICOM MYCS security solutions & services with many more benefits. Your Unique Username: $m & Password: $p. For any queries /assistance pls call 1800-270-4567 (Currently available only for Android users)";
答案 1 :(得分:0)
您只需使用' \'
即可转义双引号逗号$str = "test \"foobar\" test";
答案 2 :(得分:-1)
$param['msg'] = addslashes("Dear Customer, Delighted to inform you about "MYZICOM app" India's first service app in security industry . Download now and get 24*7 Service and bills management assistance for your ZICOM MYCS security solutions & services with many more benefits. Your Unique Username: $m & Password: $p. For any queries /assistance pls call 1800-270-4567 (Currently available only for Android users)");