I need to parse some saved e-mail messages. Here is the code I have so far:
#!/usr/bin/php
$dir = opendir(/home/jeff/survey/);
while (($file = readdir($dir))) {
if(is_file($file)) {
if(!($fileArray = file($file))) {
printf("could not open $file file);
}
for ($i=0; $i < count ($fileArray); $i++) {
**** NEW CODE ****
}
}
closedir($dir);
The lines of the text file look like this:
Merchandise in stock? Average
The left side information is not always the same, but the answer is always in position 56 of that line. So, I need the script to read in the left side of the information to see what line it is on, and then read the answer into a variable. I am going to write out the answers to a MySQL database. But, I have no problem writing the data out. I am just not sure how to parse the lines to see where I am in the file, and to get the answer into a variable.
Any help would be appreciated. Even if it is just pointing me in the right direction.
Thanks.