<?php
$dirs = [
"./playground",
"./sample"
];
function get_pathes_recursive($dir)
{
$result = [];
$items = scandir($dir);
foreach ($items as $item) {
if ($item === '.' || $item === '..') {
continue;
}
$path = $dir . DIRECTORY_SEPARATOR . $item;
if (is_dir($path)) {
$result = array_merge($result, get_pathes_recursive($path));
} else {
$result[] = $path;
}
}
return $result;
}
$links = [];
foreach ($dirs as $dir) {
$files = get_pathes_recursive($dir);
foreach ($files as $file) {
if (preg_match('/\.(html|php)$/', $file)) {
$links[] = $file;
}
}
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>リンク集</title>
</head>
<body>
<h1>リンク集</h1>
<ul>
<?php foreach ($links as $link): ?>
<li><a href="<?php echo htmlspecialchars($link); ?>">
<?php echo htmlspecialchars($link); ?>
</a></li>
<?php endforeach; ?>
</ul>
</body>
</html>