Suggestions for parsing this data

lypeoppob

New Member
So I have a huge file of names that has to be split into more columns for excel.So I am using PHP to parse this, so here is part of the example:\[code\]Dr. Johnny Apple SeedMs. A. P. OrangesMrs. Purple Cup\[/code\]Essentially, I want to put this into an array. I was using fopen, fget, and explode. The problem is, if I use explode, some of the arrays would not have consistent elements. For example, the first one would have a total of 4 (Dr, Johnny, Apple, Seed), the third would have only three. How would I add a fourth empty element between purple and cup? or is there a better way?This is my code:\[code\]$fp = fopen($filename,"r");if ($fp) { while (!feof($fp)) { $data = http://stackoverflow.com/questions/3869955/fgets($fp, filesize($filename)); $contents[] = explode(" ", $data) . } } fclose($fp);echo "<pre>";var_dump($contents);echo "</pre>";\[/code\]Desired Output:\[code\] array(4) { [0]=> string(4) "Mrs." [1]=> string(4) "Purple" [2]=> string(1) " " [3]=> string(8) "Cup"array(4) { [0]=> string(3) "Dr." [1]=> string(6) "Johnny" [2]=> string(5) "Apple" [3]=> string(4) "Seed"\[/code\]
 
Back
Top