PHP读取txt文档

读取txt

$local_path = "files/url.txt";
        $ch = curl_init($file_path);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        file_put_contents($local_path, curl_exec($ch));
        curl_close($ch);
        //3、打开文件
        $fileInfo = fopen($local_path, "r");
        if (!$fileInfo) {
            return ['status' => 1, 'message' => '文件无法打不开'];
        }
        //4、计算url数量
        $dataInfo = $result = [];
        while (!feof($fileInfo)) {
            $redeem_code = trim(fgets($fileInfo));
            if (preg_match("/^[0-9a-zA-Z][0-9a-zA-Z\-]{3,31}$/", $redeem_code)) {
                $dataInfo[] = $redeem_code;
            }
        }
        fclose($fileInfo);
        if (empty($dataInfo)){
            return ['status' => 1, 'data' => "号码包格式不正确"];
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章