問題描述
我目前正在使用下面的代碼嘗試從 random.txt
中讀取隨機行并將其作為 $data
傳遞,但它返回空.每個字符串都有自己的行,我在這里遺漏了什么嗎?這不應(yīng)該工作嗎?如果不是,我如何從我的文本文件中獲取隨機行并將其用作我的 $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以為我已經(jīng)仔細(xì)檢查過了,很抱歉提出問題.
Solved - Bad CHMOD Thought I had double checked it, sorry to post a question.
推薦答案
確保您的文件設(shè)置了讀取權(quán)限,應(yīng)該 CHMOD 為 644 或 744.
Make sure your file has read permissions set, should be CHMOD'd to 644 or 744.
這篇關(guān)于從 TXT 文件中提取隨機行作為字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!