Hello!
Our Patient-Mgmt system exports Patient admission data out as a CSV file. Any text-fields have speech-marks around them, and any number fields do not. The catch is, some of the text fields have commas in. I am trying to figure out how to Explode the lines into an array, so I can manipulate them, but I'm a bit stuck. I can't use comma as the delimiter, as the commas in some of the fields stuff it up. I can't use <speech-mark comma speechmark> as not all fields have speech marks.
An example of the data is
"CCU",20010608,"MOUSE","MICKEY, THE", 19540204
Here's my code so far.
while (list($key, $val) = each ($file))
{
$val = ereg_replace('\"', "", $val);
$data = explode(",", $val);
echo "pWard= $data[1], pSurname = $data[3], and pFirstname = $data[4]<br>"; //test to see if the data has matched properly
} // end While (list($key...
Ideally I want a way of reading in by comma, but if it hits a speech mark, ignoring commas until it hits the next speech mark. Do I need to do some code to read each character, check if it's a speech-mark or a comma, then build the $data[] array accordingly?
ANy ideas would be appreciated!
Darren