我目前正在使用下面的代码尝试从 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模板网!
以编程方式将可下载文件添加到 Woocommerce 产品Add programmatically a downloadable file to Woocommerce products(以编程方式将可下载文件添加到 Woocommerce 产品)
获取今天 Woocommerce 中每种产品的总订单数Get today#39;s total orders count for each product in Woocommerce(获取今天 Woocommerce 中每种产品的总订单数)
在 WooCommerce 和电话字段验证问题中添加自定义注Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和电话字段验证问题中添加自定义注册字段
在 Woocommerce 简单产品中添加一个将更改价格的选Add a select field that will change price in Woocommerce simple products(在 Woocommerce 简单产品中添加一个将更改价格的选择字段)
在 WooCommerce 3 中将自定义列添加到管理产品列表Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中将自定义列添加到管理产品列表)
自定义结帐“下订单"按钮输出htmlCustomizing checkout quot;Place Orderquot; button output html(自定义结帐“下订单按钮输出html)