Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php function getRandomTxtFile($directory) { // 确保目录路径以斜杠结尾 $directory = rtrim($directory, '/') . '/'; // 获取目录中所有的 txt 文件 $files = glob($directory . '*.txt'); // 检查是否有 txt 文件 if (empty($files)) { return "没有找到 txt 文件。"; } // 随机选择一个文件 $randomFile = $files[array_rand($files)]; // 返回文件的完整路径 return $randomFile; } // 使用示例 $directory = 'sitemapall/kaiyuncc'; $randomTxtFile = getRandomTxtFile($directory); echo $randomTxtFile;
Copy Clear