php - 如何使用 php 以正确的格式发送短信?
问题描述
在这段代码中,我使用短信网关向客户端发送消息。现在,短信发送成功,但格式看起来很简单:
This is a remainder about the title by the 2019-11-11 hello
看起来很简单我想显示的消息应该是这样的:
This is a remainder about
the title
by 2019-11-11
hello
行应该在about
,title
和之后date
换行message
那么我该怎么做呢?请帮我。
谢谢你
$message = "This is a reminder about the ".$this->input->post("title")." by the ".date("Y-m-d", strtotime($this->input->post("date")))." ".strip_tags(html_entity_decode($this->input->post("notice")))."";
$requestParams = array(
'user' => '**********',
'pass' => '**********',
'sender' => '*******',
'phone' => trim(json_encode($student_phone, JSON_NUMERIC_CHECK),'[]'),
'text' => $message,
'priority' => 'ndnd',
'stype' => 'normal'
);
$apiUrl = "http://bhashsms.com/api/sendmsg.php?";
foreach($requestParams as $key => $val){
$apiUrl .= $key.'='.urlencode($val).'&';
}
$apiUrl = rtrim($apiUrl, "&");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$return = json_encode($result);
解决方案
尝试使用“新行”字符\n
。像这样将它插入到字符串中:
$message = "This is a reminder about \n the ".$this->input->post("title")."\n by the ".date("Y-m-d", strtotime($this->input->post("date")))."\n".strip_tags(html_entity_decode($this->input->post("notice")))."";
推荐阅读
- powershell - Powershell - 使用哈希表合并来自两个变量的值
- flutter - 注销后处理/重置提供程序
- node.js - 在 WebStorm 中调试 TypeScript Node 项目不会在断点处停止
- abp - abp.io 使用 CreateModalModel 添加新记录的问题
- sql - 声明一个将 Date 数据类型转换为 Integer 的变量
- python - 合并来自多个excel文件的数据
- unity3d - 为什么纹理的文件图像大小与在 Unity 中加载时的大小不同?
- c - 如果给出了行号,如何从文件中打印文本?
- wordpress - WooCommerce 中的圆形购物车小计
- javascript - IntroJS,在移动视图上 IntroJS 没有突出显示特定元素!无法正常唤醒,请参阅