douju2599 2014-06-16 09:17
浏览 9
已采纳

无法使数组生效

first sorry for my english I have array will used by function

  1. Upload text file and every line will be element in array

    $fh = fopen("upload/".'1.txt','r');
    $conn = array();
    while ($line = fgets($fh)) {
        $conn[] = $line;
    }
    fclose($fh);
    $wbs->SendBulk($conn, "hello world");
    
  2. Go To Function

    public function SendBulk($targets, $message)
    {
        echo "Sending " . count($targets) . " bulk messages...<br />";
    
        foreach($targets as $target)
        {
            $this->wa->sendPresenceSubscription($target);
            $this->wa->pollMessages();
            $this->wa->sendMessageComposing($target);
            sleep(55);
            $this->wa->pollMessages();
            $this->wa->sendMessagePaused($target);
            static::$sendLock = true;
            echo "Sending message from " . $this->username . " to $target... ";
            $this->wa->sendMessage($target, $message); // Orginal
            while(static::$sendLock)
            {
                //wait for server receipt
                sleep(55);
            }
        }
    

My Problem If I have in text file 2 or more element in array will send for the last element a message but If i make array like this

$conn= array("565684898", "484849815", "484897987", "515498798");

It work for all elements Please Help

  • 写回答

1条回答 默认 最新

  • dragon8837 2014-06-16 09:30
    关注

    The string returned by fgets() includes the newline that ends each line. Use rtrim() to remove it:

    $conn[] = rtrim($line);
    

    You can also replace your entire code that reads the file with:

    $conn = file('upload/1.txt', FILE_IGNORE_NEW_LINES)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c