Hi all, I have a text file which each field is seperated by comma. And each field can contain either numeric character or non-numeric character(which is
surrounded by a pair of double quotes). But my problem is: if I seperate the fields using comma, then the address field will be seperated into 2 array elements
array, since my address field itself contains comma. How do I get around the problem?
csv_file
"john smith","male",34,"403,Pinewood Avenue, Toronto",,"CN"
"janice robinson","female","209 Q Street, Davis",5,"US"
$str = "\"john smith\","male",34,\"403, Pinewood Avenue,Toronto\",,,\"CA\"";
echo $str;
$split = preg_split("/[a-z0-9]*\,/", $str);
echo "<pre>";
print_r($split);
echo "</pre>";
Many thanks