This is a good code:
<?php
echo "<ul class=\"flexmenu\">\n";
$phpfiles = glob("$path./[^index]*.php"); // Get all PHP files except index.php
foreach ($phpfiles as $phpfile) {
$contents = file_get_contents($phpfile);
preg_match('/\$title\s*=\s*"(.*?)";/', $contents, $titleMatch);
preg_match('/\$subtitle\s*=\s*"(.*?)";/', $contents, $subtitleMatch);
preg_match('/\$description\s*=\s*"(.*?)";/', $contents, $descriptionMatch);
preg_match('/\$order\s*=\s*"(.*?)";/', $contents, $orderMatch);
$title = $titleMatch[1] ?? 'No title';
$subtitle = $subtitleMatch[1] ?? 'No subtitle';
$order = $orderMatch[1] ?? '';
$description = $descriptionMatch[1] ?? 'No description';
// Correctly extract the filename
$filename = $phpfile; // Use basename on $phpfile directly
echo " <li role='menuitem' style=\"order:$order\"><a href=\"{$filename}\">{$title}</a>, <i>{$subtitle}</i>: {$description}</li>\n";
}
echo "</ul>";
?>
You can get the title of your files in that folder (useful if the name of the file would not suit for a list), the subtitle and description.
With the order variable you can set, in a flex list (and this is why is added a .flexmenu class: a no-flex list doesn’t order your items as expected, but alphabetically), in what order your files should appear.
Of course the title is linked with the matching file.