I have written this nice'n'simple script to look for files in a folder that are related to the current page. If found, the .php extension is trimmed off as well as everything but the last character. If the last character is a number, it is echoed out as a link to display the next page in the series.
Here it is:
Code: Select all
if ($handle = opendir('includes')) {
while (false !== ($file = array(readdir($handle)))) {
$i=0;
foreach($file as $num){
//strip off the .php extension
$stripped=substr($num, 0, -4);
//echo "$stripped\n";
$pagename=$_GET['pagename'];
if(eregi($pagename,$stripped)){
$start=strlen($stripped)-2;
$num=substr($stripped, -1, $start);
if(is_numeric($num)){
echo "<a href=\"$PHP_SELF?pagename={$pagename}_$num\">".$num."</a> ";
}
// exit();
}
}
}
closedir($handle);Secondly, how do I sort the results of the script? It works perfectly but, assuming there are three files to link to, instead of returning 1 2 3, I get 1 3 2. Is there a function to fix this?
Thanks in advance!!
Matt