Php 将数组拆分为字符串以发送批量sms codeigniter
我有一个功能用来发送短信,它的工作很好。这是我使用的函数:Php 将数组拆分为字符串以发送批量sms codeigniter,php,arrays,codeigniter,Php,Arrays,Codeigniter,我有一个功能用来发送短信,它的工作很好。这是我使用的函数: function send_sms() { $acc = $this->input->post('acc'); $key = $this->input->post('key'); $to = $this->input->post('to'); $sms = $this->input->post('sms');
function send_sms() {
$acc = $this->input->post('acc');
$key = $this->input->post('key');
$to = $this->input->post('to');
$sms = $this->input->post('sms');
$url = "http://host.com/public/sms.api?acc=". $acc ."&key=". $key ."&to=". $to ."&sms=" . $sms;
$this->load->helper('html');
echo link_tag($url);
echo 'SMS Sent, thank you';
}
现在,我想向多个号码发送短信。这些数字来自我的数据库。但是我的电话号码没有收到留言
这是我拥有的发送批量短信的功能:
function send_bulk_sms() {
$search_by = $this->input->post('search_by');
if ($search_by == 'prefer_location') {
$location = $this->input->post('search_field');
$recipients_array = $this->company_model->search_by_location($location);
$recipients = array();
foreach ($recipients_array as $key => $value) {
$recipients[] = $value['phone'];
}
} elseif ($search_by == 'sector') {
$sector = $this->input->post('search_field');
$recipients_array = $this->company_model->search_by_sector($sector);
$recipients = array();
foreach ($recipients_array as $key => $value) {
$recipients[] = $value['phone'];
}
}
$acc = $this->input->post('acc');
$key = $this->input->post('key');
$to = $recipients;
$sms = $this->input->post('sms');
$url = "http://host.com/public/sms.api?acc=" . $acc . "&key=" . $key . "&to=" . $to . "&sms=" . $sms;
$this->load->helper('html');
echo link_tag($url);
echo 'SMS Sent, thank you';
}
数据库中的$recipients值如下所示:
$to = array(
'02158745',
'02158745'
);
$to = '02158745';
阵列[0]=>03-56122223[1]=>02158745
我已尝试将$更改为以下值:
$to = array(
'02158745',
'02158745'
);
$to = '02158745';
还是像这样
$to = array(
02158745,
02158745
);
他们两个都不工作。当我尝试将$更改为值时,它会起作用,如下所示:
$to = array(
'02158745',
'02158745'
);
$to = '02158745';
有没有办法将数组值拆分为字符串?
或者如何发送带有$recipients号码的短信
谢谢。尝试阵列漫游功能-
为什么不在阵列中循环并为每个号码调用send_sms功能?我认为这取决于您使用的sms服务提供商。指定多条sms的格式将在其开发人员文档中。API的提供商是否支持您传递数组?你不能决定你想通过什么考试。请参阅他们的API文档。也许他们对批量短信有不同的API,短信服务可以发送多条短信。但当我尝试时,它不起作用。有什么建议吗?好了,不要把$to作为数组传递,而是把它作为逗号分隔的列表传递:$to=introde',',$to;