Приведенный ниже код выберет все мои файлы php из указанной папки, а затем перетасует их и выведет 10 результатов на мою страницу, папка содержит файл index.php, который я хотел бы исключить из результатов.
<?php
if ($handle = opendir('../folder/')) {
$fileTab = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$fileTab[] = $file;
}
}
closedir($handle);
shuffle($fileTab);
foreach(array_slice($fileTab, 0, 10) as $file) {
$title = str_replace('-', ' ', pathinfo($file, PATHINFO_FILENAME));
$thelist .= '<p><a href="../folder/'.$file.'">'.$title.'</a></p>';
}
}
?>
<?=$thelist?>
Я нашел код для исключения index.php, но я не уверен, как включить его в мой код выше.
<?php
$random = array_values( preg_grep( '/^((?!index.php).)*$/', glob("../folder/*.php") ) );
$answer = $random[mt_rand(0, count($random) -1)];
include ($answer);
?>
glob
. - person Joseph Silber   schedule 21.01.2013