The code below opens a file in readonly mode. Each line is chopped up and stuffed into an array and pushed top a list. (multi dementional array).
The problem I'm having is stripping out the quotes from the data. I can get it take the first and last quotes off but I can't reach any in the middle.
Does anyone know of an elegant was to do this? I could loop through the array and strip it one by one but I would like to processes it as it comes in.
If it matters at all later I will be formating the values (int, int, date).
I used to code in ANSI C years and years ago but, wow, have I lost the touch.
cheers
/*****************************************************
This program will open a file and force it in to an
array based on a predefined template.
**
/
$sourcefile = "File.txt";
$stack = array ();
$temp = array();
$fp = fopen ($sourcefile, "r");// || die("<br><b>Cannot open input file please check your path</b><br><br>$sourcefile");
while (!feof ($fp)) {
// use split , to tokenize the line. use list (...) insert tokens in to temp array
list($temp['File'], $temp['Priority'], $temp['Entered']) = split (",",trim(strtr(fgets($fp, 4096),"\"","")));
array_push ($stack, $temp);
//Debug line to see array
printf("|%s| |%s| |%s|<br>",$temp['File'], $temp['Priority'], $temp['Entered']);
}
fclose ($fp);
out put to screen
|"1"| |"1"| |"1/2/2002"|
|"4"| |"4"| |"4/8/2002"|
|"3"| |"3"| |"3/2/2002"|
|"9"| |"2"| |"6/6/2002"|
|"5"| |"5"| |"5/2/2002"|
|"6"| |"5"| |"5/3/2002"|
|"7"| |"5"| |"5/4/2002"|
|"8"| |"5"| |"5/1/2002"|
Input file
"1","1","1/2/2002"
"4","4","4/8/2002"
"3","3","3/2/2002"
"9","2","6/6/2002"
"5","5","5/2/2002"
"6","5","5/3/2002"
"7","5","5/4/2002"
"8","5","5/1/2002"