I've tried numerous solutions to my problem, but to no avail.
1st off tried fgetscsv but as my flat text file doesn't have enclosure delimters and fgetcsv doesn't do well with line feeds I tried this parser class, however that once again borked at the line feeds.
So I wrote some simple code to try and trouble shoot, and that once again takes line feeds as record delimiters but this still has the same problem, namely splitting at the line feed and not the delimiter !
Code is:
<?php
$delimiter = chr(1);
$fp = fopen('app2','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
$loop = 0;
while (!feof($fp)) {
$loop++;
$line = fgets($fp,2048); //use 2048 if very long lines
$field[$loop] = explode ($delimiter, $line);
echo '
<tr>
<td>'.$field[$loop][0].'</td>
<td>'.$field[$loop][1].'</td>
<td>'.$field[$loop][2].'</td>
<td>'.$field[$loop][3].'</td>
<td>'.$field[$loop][4].'</td>
<td>'.$field[$loop][5].'</td>
<td>'.$field[$loop][6].'</td>
<td>'.$field[$loop][7].'</td>
<td>'.$field[$loop][8].'</td>
<td>'.$field[$loop][9].'</td>
<td>'.$field[$loop][10].'</td>
<td>'.$field[$loop][11].'</td>
<td>'.$field[$loop][12].'</td>
<td>'.$field[$loop][13].'</td>
<td>'.$field[$loop][14].'</td>
<td>'.$field[$loop][15].'</td>
<td>'.$field[$loop][16].'</td>
</tr>';
$fp++;
}
fclose($fp);
?>
If I open up the text file in vi it shows various characters:
#export_date^Aapplication_id^Atitle^Arecommended_age^Aartist_name^Aseller_name^Acompany_url^Asupport_url^Aview_url^Aartwork_url_large^Aartwork_url_small^Aitunes_release_date^Acopyright^Adescription^Aversion^Aitunes_version^Adownload_size^B
#primaryKey:application_id^B
#dbTypes:BIGINT^AINTEGER^AVARCHAR(1000)^AVARCHAR(20)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^ADATETIME^AVARCHAR(4000)^ALONGTEXT^AVARCHAR(100)^AVARCHAR(100)^ABIGINT^B
#exportMode:FULL^B
1276678802857^A371515175^ALAROUSSE Pâtissier^A4+^AEditions Larousse^AEditions Larousse^A^Ahttp://www.larousse.fr/infos/ipad^Ahttp://itunes.apple.com/app/id371515175?uo=5^Ahttp://a1.phobos.apple.com/us/r1000/044/Purple/b4/3a/34/mzl.utpthqib.100x100-75.jpg^Ahttp://a1.phobos.apple.com/us/r1000/052/Purple/68/2d/b0/mzl.wkhtezdb.png^A2010 05 13^ALAROUSSE^AAvec le Petit Larousse Pâtissier sur iPad, découvrez une nouvelle expérience en cuisine!^M
^M
Un livre plébiscité et primé :^M
– World Cookbook Awards – ^M
Special Award of the Jury^M
^M
Feuilletez, craquez devant les photos et choisissez votre recette ! C’est facile, un clic et vous tournez la page !^M
^M
My code is taking the character after cuisine as a delimiter, and not keeping all the description text together. So every M it is taking as a record delimiter.
I don't care how it's done to be honest, so if anyone wants to recommend another way to solve the problem I'd be chuffed! The only constraint is that the file is given to me as is so I cannot change the source.