讀取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' => "號碼包格式不正確"];
}