本文介紹了從 TXT 文件中提取隨機行作為字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我目前正在使用下面的代碼嘗試從 random.txt
中讀取隨機行并將其作為 $data
傳遞,但它返回空.每個字符串都有自己的行,我在這里遺漏了什么嗎?這不應該工作嗎?如果不是,我如何從我的文本文件中獲取隨機行并將其用作我的 $data
字符串?
I'm currently using the code below to try and read a random line from random.txt
and pass it as $data
, however it comes back empty. Each string has its own line, am I missing something here? Shouldn't this work? If not how can I get a random line from my text file and use it as my $data
string?
$f_contents = file("random.txt");
$line = $f_contents[array_rand($f_contents)];
$data = $line;
已解決 - 錯誤的 CHMOD以為我已經仔細檢查過了,很抱歉提出問題.
Solved - Bad CHMOD Thought I had double checked it, sorry to post a question.
推薦答案
確保您的文件設置了讀取權限,應該 CHMOD 為 644 或 744.
Make sure your file has read permissions set, should be CHMOD'd to 644 or 744.
這篇關于從 TXT 文件中提取隨機行作為字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!