This flatfile business will get you big, big headaches.
It's not scalable, doesn't perform well, and is generally very irritating to use.
I strongly (very strongly) advice that you start using a databases instead.
Now on with your problem.
This next bit is quite a complex piece of 'doing it the hard way'
$i = 1;
while ($i <= $rec_num):
list ($key[($i)-1], $name[($i)-1], $email[($i)-1], $date[($i)-1], $body[($i)-1]) = split("|",$record[($i)-1]);
$i++;
endwhile;
For starters, why do you start with $i=1, only to subtract 1 every time you use it?
And why is the $i always in parenthesis?
try this:
i = 0;
while ($i <= $rec_num)
{
list ($key[$i], $name[$i], $email[$i], $date[$i], $body[$i]) = split("|",$record[$i]);
$i++;
};
Next problem, the regexp error.
This is because split() takes a regular expression as a pattern, and "just a |" is not avalid pattern. The 'pipe' is an operator inside regular expressions, so just putting "|" is like expecting PHP to understand a script that just contains "or".
To get it working you must 'escape' the pipe character like this:
split("|",$records[$i])
The backslash tells split that you really mean the | character, and not the operator it represents.
Moving on a bit further, why are you making seperate arrays for key/name/email/date/body?
You could also create one big associative array like this:
list($aTable[$i]['key'], $aTable[$i]['name'], $aTable[$i]['email']) = split("|", $record[$i]);
Then you can access any row of the 'table' like this:
echo "His name is ".$aTable[$iRow]['name']." and his key is ".$aTable[$iRow]['key'];
that is a lot easier to understand.