From 601accf7a7ecb85a8215e85b24bc8a07b55cc01e Mon Sep 17 00:00:00 2001 From: LyLme Date: Tue, 19 Dec 2023 00:33:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B01.8.0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/function.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/include/function.php b/include/function.php index bab01c2..3e49226 100644 --- a/include/function.php +++ b/include/function.php @@ -212,16 +212,12 @@ function get_real_ip() function yan() { $filename = ROOT . '/assets/data/data.dat'; - //随机一言文件路径 - if (file_exists($filename)) { - $data = explode(PHP_EOL, file_get_contents($filename)); - // $result = str_replace(array( - // "\r", - // "\n", - // "\r\n" - // ), '', $data[array_rand($data)]); - return $data[array_rand($data)]; - } + $data = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + // 随机获取一行索引 + $result = $data[array_rand($data)]; + // 去除多余的换行符 + $result = str_replace(["\r", "\n", "\r\n"], '', $result); + return $result; } function rearr($data, $arr) {