用PHP加载随机的.html文件? [英] Load in random .html file with PHP?

查看:118
本文介绍了用PHP加载随机的.html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,其中包含几个html文件:1.html2.html3.html等等等,依次排列.

I have a folder which contains several html files: 1.html, 2.html, 3.html, etc., etc. in sequential order.

我希望PHP将这些文件随机加载到我拥有的PHP网页中.我该怎么做呢?

I would like for PHP to randomly load in these files into a PHP webpage that I have. How can I go about doing this?

也-PHP是执行此操作的最有效方法吗? jQuery会更好吗?

Also -- is PHP the most efficient way to do this? Would jQuery be better?

推荐答案

jquery可以做到,但是您必须事先将可用文件列表发送给客户端,因此它有一个列表可供选择.如果您不能保证文件中绝对不会出现空洞",则需要这样做. 1,2,4,5(嘿,哪里是3?).

jquery could do it, but you'd have to send a list of the available files to the client beforehand, so it has a list to choose from. This would be required if you can't guaranteed there'll never be "holes" in the files, e.g. 1,2,4,5 (hey, where's 3?).

PHP可以处理原始文件系统,并且始终可以获取文件列表,例如

PHP can deal with the raw filesystem, and can always get the list of files, e.g.

<?php
$files = glob('*.html');
$random_file = $files[array_rand($files)];
include($random_file);

这将处理任何.html文件,而不考虑编号顺序中的孔,甚至根本没有编号.

This will handle any .html file, regardless of holes in the numbering sequence, or even if they're numbered at all.

这篇关于用PHP加载随机的.html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆