【发布时间】:2015-05-12 08:42:40
【问题描述】:
我正在尝试拆分一个字符串以保持在 70 个字符的限制以下...但是,当我这样做时,我的循环会在它获得前 70 个字符时停止并且它不会尝试执行第 2 组。我走这条路而不使用str_split 的原因是为了保留整个单词,所以我不会用半个单词发送消息。如果第二次拆分少于 70 个字符,请仍将其发送出去...非常感谢任何形式的帮助。
$message="A new powerful earthquake convulsed the traumatized nation of Nepal on Tuesday, leveling buildings already damaged by the devastating quake that killed thousands of people less than three weeks ago."
$msg = explode(' ',$message);
foreach($msg as $key) {
$keylen = strlen($key);
$msglen = $msglen + $keylen;
if($msglen<70) {
$msgs .=$key." ";
// $agi->verbose("$msgs");
} else {
$params = array(
'src' => '18009993355',
'dst' => $callerid,
'text' => $msgs,
'type' => 'sms',
);
// $agi->verbose("sending: $msgs");
$response = $p->send_message($params);
$msgs = "";
$msglen = 0;
}
}
【问题讨论】:
-
能否请您连同字符串一起更新您的问题
-
如果没有 $message,我们将无能为力,对不起。
-
为什么你说的是 70 个字符并与
$msg<50比较??? -
如我所见,如果 $message 少于 50 个字符,它将永远不会被发送
-
添加了 $message.. 如果第二条消息有 30 个字符...仍然发送出去.. 只是不要发送超过 70 个字符的消息...