I have this code that i use for a navigation bar:
<?php
$url = 'snip';
foreach (glob("pages/*") as $path1) {
$file1 = basename($path1);
$file2 = end(explode('_', $file1));
echo "<div class=\"navbutton\"><a style=\"color:#333333;\" href='{$url}index.php?page={$file1}'>$file2</a></div>";
}
?>
My folder looks like:
pages/
1_Home
2_About
404
I do not want it to include the file "404", is there a way i can remove it from the variable? Unset doesnt work for some reason.
Your file glob pages/*
of course matches all files in the pages
directory. Since everything except the 404
page contains an underscore in the filename, the simplest solution to drop in place is a slightly smarter file glob which only matches those having an underscore, like:
pages/*_*
So:
foreach (glob("pages/*_*") as $path1) {
// Everything else is the same
}