在PHP中随机选择文件 [英] Randomly select file in PHP
本文介绍了在PHP中随机选择文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在php中使用'include'关键字从文件夹中随机选择一个文件并输出内容。如何做到这一点?
谢谢。
解决方案
知道文件所在的文件夹,文件是PHP文件:
$ p $ $ phpFiles = glob('/ path / to / 。文件/ * PHP的');
if(empty($ phpFiles)=== false)
{
$ randomFile = $ phpFiles [array_rand($ phpFiles)];
包括($ randomFile);
}
I'd like to use the 'include' keyword in php to randomly select a file from a folder and output the contents. How would I do this?
Thanks.
解决方案
Assuming you know the folder where the files are and that the files are PHP files:
$phpFiles = glob('/path/to/files/*.php');
if (empty($phpFiles) === false)
{
$randomFile = $phpFiles[array_rand($phpFiles)];
include($randomFile);
}
这篇关于在PHP中随机选择文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文