This year I told my mom that I'd try to type up her recipes that she'd collected over several years as a Christmas present of sorts. However, due to some computer issues, and the sheer volume of recipes she had, I'm not going to have them all done by Christmas time, so I figured the second best option I had until I could get them all typed was to make a well-organized listing of the scans I made.
While I have the basic file listing made up, it's not easily searchable and kind of bland.
My ultimate goals are the following:
- Get the files from the directory and store them in an array (Done)
- Sort The Files Alphabetically (Done)
- Remove The File Extensions From The Display Name, While Retaining It For The Link (Done)
- Replace the underscores in the displayed file name with spaces
- Turn Each Entry into a Link To The HTML or JPG file (Done)
- Subdivide Links By The First Letter of the File Name
- Add A "To Top" Link at the bottom of each category (I know how to do this, but I need the subdivision first)
- Create A List of each Letter at the top of the page with the anchor link to the start of that category (I can do this once I have the subdivision worked out.)
After looking online for a while, I have had absolutely no luck finding code that will do the subdivision by first letter that will work with the rest of my code. (There is code out there, but either the code I've pieced together doesn't call information in the right way, or I'm trying to merge the two codes incorrectly.)
I haven't yet looked for any code to replace the _ with spaces in the file name, because, to be honest, that's really just me being anal retentive. It's the least important entry in this list, but all the same, any help would be greatly appreciated.
Considering it's been a couple of years since my PHP class and I haven't used it regularly, I'm a bit rusty. I've been thinking that perhaps my best option is a bunch of functions, and then calling them at the very end, but I'm definitely up for constructive criticism on that thought.
While I love challenges, and normally don't like asking for help because I don't learn through doing that way (which is the way I learn), I work retail, and I know that the rest of this month is going to take it out of me both mentally and physically so I'm begging for mercy here.
This is the code that I do have, taken and modified from multiple sites online.
PHP Code:
<?php
function RemoveExtension($strName)
{
$ext = strrchr($strName, '.');
if($ext !== false)
{
$strName = substr($strName, 0, -strlen($ext));
}
return $strName;
}
// Creates an array that will store all of the files
$dirFiles = array();
// opens the folder
if ($handle = opendir('./directory/HTML/chris_oslers_recipes')) {
while (false !== ($file = readdir($handle))) {
// Strips out the parent directory and the index file.
if ($file != "." && $file != ".." && $file != "index.php" && $file != "Thumbnails") {
$dirFiles[] = $file;
}
}
closedir($handle);
}
// Sorts the files alphabetically
sort($dirFiles);
// Creates a link for each file.
foreach($dirFiles as $file)
{
echo "<li><a href=\"http://www.brianosler.com/recipes/directory/HTML/chris_oslers_recipes/$file\">" . RemoveExtension($file) . "</a></li>";
}
?>