PHP reading a csv file effectively
<p>There are a few ways to read CSV files with PHP. I used to use the <em>explode</em> fucntion to put each line into an array and then <em>explode</em> commas and use <em>trim</em> to remove any quotation marks from around the data. It was messy...</p>

<p>In PHP 5 there's now <em>fgetcsv</em> and *str_getcsv*... I'm guessing this is the best way to go about it these days so I've whipped together some code...</p>

<pre><code>$fp = fopen($csv_file['file_path'], 'r');       
while (($data = fgetcsv($fp, 0, "\r", '"', "\r")) !== FALSE) {
    $num = count($data);
    for ($c=0; $c &lt; $num; $c++) {
        print_r(str_getcsv($data[$c]));
    }
}
</code></pre>

<p>It seems to work but is there a more fail safe approach? For example making it work whether line breaks are \n or \r...</p>

<p>Any input you can give would be awesome!</p>
