tags:

views:

19

answers:

0

I have written some small code to read in a flat text file and display it. My issue is that one of the fields has alot of text in it and also some line returns. My code is using the line return is a delimiter and moving onto the next record.

How can I tell it to only split by the delimiter and ignore line returns?

Sample code I am using:

$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);
?> 

You can see what it is doing here http://www.smartphonesoft.com/fred/xmlfeed/test/itunes_to_mysql.php