Your approach is one way of doing it. You could scan the directory for the files you need, and use the file()
function to retrieve file contents in an array. I will only post partial code, as getting file names from a directory is obvious (see glob()
in other answers).
//got file list from a given directory in an array (array would contain file names).
//it is recommanded, that file names to be with full path, or a relative path to the script
$task_array = Array();
foreach ($filelist as $filename)
{
try
{
$file_content = file($filename); // we get an array with this function
// you could do this the other way, by using fopen() and fread(), but this is easier
}
catch(Exception $e)
{
$(file_content = false;
}
if (($file_content !== false) && (!empty($file_content)))
{
$task_array[] = $file_content;
}
}
Your task array will become a two-dimensional array, like this:
Array(
[0] -> Array(
[0] -> 1
[1] -> 'Lesson Title'
[2] -> 'Lesson Description here'
[3] -> '2013-09-25'
)
[1] -> Array(
[0] -> 2
[1] -> 'Lesson Title 2'
[2] -> 'Lesson 2 Description here'
[3] -> '2013-09-25'
)
)
Then, when you have this array, you could use foreach again, to display it in HTML.
However, if you would want to do this the right way, you should use a database, for example MySQL.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…