Php Sms网关foreach错误
谁能帮帮我吗。 我想为sms网关创建php脚本,但foreach命令有问题。 我找不到什么 这是我的密码:Php Sms网关foreach错误,php,foreach,sms-gateway,Php,Foreach,Sms Gateway,谁能帮帮我吗。 我想为sms网关创建php脚本,但foreach命令有问题。 我找不到什么 这是我的密码: <?php $url = 'http://www.freesmsgateway.com/api_send'; $post_contacts = array('381645391312', '0646395732', '99381625597222'); //phone numbers xxxxxxxxxx format $json_contacts =
<?php
$url = 'http://www.freesmsgateway.com/api_send';
$post_contacts = array('381645391312', '0646395732', '99381625597222'); //phone numbers xxxxxxxxxx format
$json_contacts = json_encode($post_contacts); //encode them to json
$fields = array(
'access_token'=>'53f86041s38544544e482b956bcac006',
'message'=>urlencode('Test sms poruka'),
'send_to'=>'post_contacts', //existing_contacts or post_contacts
'post_contacts'=>urlencode($json_contacts),
);
$fields_string = '';
foreach($fields_string as $key=>$value) { $fields_string .= $key.'='.$value.'&';}
//rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); //optional
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
print $result; //optional
?>
$fields\u string
是一个字符串,而不是数组,您刚刚将其初始化为空。也许您想在这里迭代$fields
?我不是php专家,但脚本必须使用$fields数组并分别获取变量。并使用$post_contacts将信息发送至号码。这是api开发人员部分的代码。如何使这个代码工作?呃…对!实际上,$fields
可能是您想要迭代的内容,而不是$fields\u string
$fields\u string='';foreach($key=>$value的字段){$fields.=$key.='.$value.&';}
无错误。这是正确的吗?不。仔细想想你写的东西…
Warning: Invalid argument supplied for foreach() in /home/user/public_html/sms/smsfreegateway.php on line 15
The message was blank.
foreach($fields_string as $key=>$value)