'Read a recipe to an array

I am trying to create a recipe site and I have hit a wall. I have recipes in .txt files in one directory and I need to scan the directory, read and store the ingredients (Flour, eggs, Milk etc) in an array, and also include the amounts of each so that they can be compared to what is requested by the user. I have got a section that scans the directory and lists thumbnails of the available recipes but I cannot think how to set the arrays so that I can list each item to an Onclick event that adds so much of each to a bowl. I don't want the quantities displayed, they are only for cross reference towards the end.

An example recipe file:

 • 250g plain flour
 • 50g icing sugar
 • salt
 • 1 lemon
 • 125g butter
 • 1 large egg
 • a splash of milk for the filling
 • 5 large apples
 • 3 tablespoons sugar
 • ½ teaspoon ground ginger 
 • a handful of sultanas 
 • ½ a lemon

To scan and display the available recipes I have:

<?php 

    $count = 0;
    $recipes = opendir('Recipes'); 
    while (false !== ($recipe = readdir($recipes))) {
        if($recipe != "." && $recipe != "..") {
            $value = str_replace(".txt","",$recipe);
            
            echo  '<td> <img src="../Recipe/Images/'; 
            echo $value;
            echo '.jpg" width="50" height="50" onclick="show(\'';
            echo $value;
            echo '\'); $recipe; return false"; alt="';
            echo $value;
            echo '" /></td>';
            $count++;
        }
    }
    echo '</tr></table>';
    
    echo '<p>You have '.$count .' recipes to chose from</p>';
    closedir($recipes);
?>

Can anyone point me right please?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source