while循环中的Php错误问题
我有一个SMS Api,它用php向我的客户发送SMS(不是电子邮件)。现在,我正在尝试从存在所有联系人号码的.txt文件发送sms: My.txt文件while循环中的Php错误问题,php,Php,我有一个SMS Api,它用php向我的客户发送SMS(不是电子邮件)。现在,我正在尝试从存在所有联系人号码的.txt文件发送sms: My.txt文件 shibbir, 8801678877639 babu, 8801534552503 我的while循环是这样的: $file_handle = fopen("$file", "r"); while ( !feof( $file_handle ) ) { $line_of_text = fgetcsv($file_handle, 10
shibbir, 8801678877639
babu, 8801534552503
我的while循环是这样的:
$file_handle = fopen("$file", "r");
while ( !feof( $file_handle ) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$line_of_text[1] ."<BR>";
$obj = new Sender("myservername","myport","username","password","$sender", "$msg",
"$line_of_text","2","1");
$obj->Submit();
echo "<div class='success'>Successfully sent your message to " . $line_of_text[1] . " Thank
You.</div>";
}
fclose( $file_handle );
Notice: Array to string conversion in D:\Software Installed\xampp\htdocs\evan\toplevel
\bulksms.php on line 108
Notice: Undefined offset: 1 in D:\Software Installed\xampp\htdocs\evan\toplevel\bulksms.php on
line 106
Notice: Undefined offset: 1 in D:\Software Installed\xampp\htdocs\evan\toplevel\bulksms.php on
line 107
我的最终目标是,用户可以通过上传所有联系人号码所在的.txt文件发送短信。因此,一旦提交了表格,那么短信必须发送到这些联系人的号码
谢谢 尝试将您的代码更改为
$file_handle = fopen("$file", "r");
while (!feof($file_handle) )
{
$line_of_text = fgetcsv($file_handle, 1024);
$line_of_text[1]=$line_of_text[1] ."<BR>";
$obj = new Sender("myservername","myport","username","password","$sender", "$msg",
$line_of_text[1],"2","1");
$obj->Submit();
echo "<div class='success'>Successfully sent your message to " . $line_of_text[1] . " Thank
You.</div>";
}
fclose($file_handle);
$file\u handle=fopen(“$file”,“r”);
而(!feof($file_handle))
{
$line\u of_text=fgetcsv($file\u handle,1024);
$line_of_text[1]=$line_of_text[1]。“
”;
$obj=新发件人(“myservername”、“myport”、“用户名”、“密码”、“$Sender”、“$msg”,
$line_of_text[1],“2”,“1”);
$obj->Submit();
echo“已成功将您的邮件发送到“$line\u of_text[1]”。谢谢
你们。”;
}
fclose($file\u handle);
1) 你们能告诉我为什么我会收到错误信息吗2)这是第二场演出 成功确认,但我想它必须显示1成功 确认
echo
DIV标记从循环中移出
$line_of_text[1] ."<BR>";
文本[1]的第行。“
”;
应该是:
$line_of_text[1] .= "<BR>";
$line\u of_text[1]。=“
”;
而且你的信息也在你的循环中,所以它会被重复多次
使用file()
和explode()
可以轻松完成此任务
$file_handle = fopen("$file", "r");
$success_number = array();
while ( !feof( $file_handle ) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$success_number[]=$line_of_text[1]; //call this statement if msg sent successfully.
$line_of_text = implode(',',$line_of_text ); // i think we need to pass string to the api.
$obj = new Sender("myservername","myport","username","password","$sender", "$msg",
"$line_of_text","2","1");
$obj->Submit();
}
echo "<div class='success'>Successfully sent your message to ".implode(',',$success_number) ."<BR> Thank You.</div>";
fclose( $file_handle );
my.php(删除了对api的调用)
这些都不是错误。它们是通知。它们还指向代码中的特定行。这段代码看起来怎么样?它是哪一行?var_dump($line_of_text)的输出是什么@MansoorkhanCherupuzha的输出是:数组(2){[0]=>string(7)“shibbir”[1]=>string(14)“8801671133639”}和数组(2){[0]=>string(4)“babu”[1]=>string(14)“8801534552503”}fgetcsv返回一个数组,然后不能像删除文本[1]的$line_语句那样将
添加到该数组中;从代码?同样,这将打印OP不想要的消息两次。@ShankarDamodaran,是的,它将打印两次,因为它们在file@Alex,让我在本地主机上测试一下。@MansoorkhanCherupuzha,现在我没有收到任何错误消息,但它没有发送短信。如果我想发送多条短信,我会在一个数字后面加逗号(,),比如:8801671144528801547744854。那么现在问题出在哪里?如果是这样,我可以在$Obj->中做些什么?@MansoorkhanCherupuzha,太好了,太好了。它向我展示了..成功地将您的消息发送到8801675886398801535884503,,谢谢。我看到了最后一个数字后面的双逗号。
shibbir, 8801678877639
babu, 8801534552503
<?php
$file = "my.txt";
$file_handle = fopen($file, "r");
$success_number = array();
while ( !feof( $file_handle ) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$success_number[]=$line_of_text[1]; //call this statement if msg sent successfully.
}
fclose( $file_handle );
echo "<div class='success'>Successfully sent your message to " . implode(',',$success_number) ."<BR> Thank You.</div>";
?>
Successfully sent your message to 8801678877639, 8801534552503
Thank You.