<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: PHP CSV to Array functions</title>
	<link>http://www.melbournechapter.net/wordpress/programming-languages/php/cman/2006/05/18/php-csv-to-array-functions/</link>
	<description>web application development with popular technologies</description>
	<pubDate>Tue, 02 Dec 2008 08:25:54 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: PBooks Open Source Accounting &#187; Blog Archive &#187; PBooks Export and Import</title>
		<link>http://www.melbournechapter.net/wordpress/programming-languages/php/cman/2006/05/18/php-csv-to-array-functions/#comment-57645</link>
		<pubDate>Thu, 26 Jul 2007 21:58:28 +0000</pubDate>
		<guid>http://www.melbournechapter.net/wordpress/programming-languages/php/cman/2006/05/18/php-csv-to-array-functions/#comment-57645</guid>
					<description>[...] Also found this which looks interesting: php-csv-to-array-functions [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Also found this which looks interesting: php-csv-to-array-functions [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Cameron Manderson</title>
		<link>http://www.melbournechapter.net/wordpress/programming-languages/php/cman/2006/05/18/php-csv-to-array-functions/#comment-16027</link>
		<pubDate>Mon, 18 Dec 2006 01:42:11 +0000</pubDate>
		<guid>http://www.melbournechapter.net/wordpress/programming-languages/php/cman/2006/05/18/php-csv-to-array-functions/#comment-16027</guid>
					<description>If you are having troubles using fgetcsv with MAC/Windows/Unix file endings, you can set the INI variable to auto detect. 

eg:

auto_detect_line_endings "0" PHP_INI_ALL Available since PHP 4.3.0.

therefore:
&lt;pre&gt;&lt;br /&gt;
ini_set(&#039;auto_detect_line_endings&#039;,&#039;1&#039;); // Will fix detection of line endings automatically&lt;br /&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>If you are having troubles using fgetcsv with MAC/Windows/Unix file endings, you can set the INI variable to auto detect. </p>
<p>eg:</p>
<p>auto_detect_line_endings &#8220;0&#8243; PHP_INI_ALL Available since PHP 4.3.0.</p>
<p>therefore:</p>
<pre>
ini_set(&#039;auto_detect_line_endings&#039;,&#039;1&#039;); // Will fix detection of line endings automatically
</pre>
]]></content:encoded>
				</item>
	<item>
		<title>by: Richard Lee</title>
		<link>http://www.melbournechapter.net/wordpress/programming-languages/php/cman/2006/05/18/php-csv-to-array-functions/#comment-1008</link>
		<pubDate>Thu, 18 May 2006 04:12:10 +0000</pubDate>
		<guid>http://www.melbournechapter.net/wordpress/programming-languages/php/cman/2006/05/18/php-csv-to-array-functions/#comment-1008</guid>
					<description>Thanks Cam just what I was looking for.

Here’s another handy function using fgetcsv() which returns an associative array - Thanks to Donovan Bray on php.net:
&lt;code&gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Based on an example by ramdac at ramdac dot org&lt;br /&gt;
 * Returns a multi-dimensional array from a CSV file optionally using the&lt;br /&gt;
 * first row as a header to create the underlying data as associative arrays.&lt;br /&gt;
 * @param string $file Filepath including filename&lt;br /&gt;
 * @param bool $head Use first row as header.&lt;br /&gt;
 * @param string $delim Specify a delimiter other than a comma.&lt;br /&gt;
 * @param int $len Line length to be passed to fgetcsv&lt;br /&gt;
 * @return array or false on failure to retrieve any rows.&lt;br /&gt;
 */&lt;br /&gt;
function importcsv($file,$head=false,$delim=&#34;,&#34;,$len=1000) {&lt;br /&gt;
   $return = false;&lt;br /&gt;
   $handle = fopen($file, &#34;r&#34;);&lt;br /&gt;
   if ($head) {&lt;br /&gt;
       $header = fgetcsv($handle, $len, $delim);&lt;br /&gt;
   }&lt;br /&gt;
   while (($data = fgetcsv($handle, $len, $delim)) !== FALSE) {&lt;br /&gt;
       if ($head AND isset($header)) {&lt;br /&gt;
           foreach ($header as $key=&#62;$heading) {&lt;br /&gt;
               $row[$heading]=(isset($data[$key])) ? $data[$key] : &#039;&#039;;&lt;br /&gt;
           }&lt;br /&gt;
           $return[]=$row;&lt;br /&gt;
       } else {&lt;br /&gt;
           $return[]=$data;&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
   fclose($handle);&lt;br /&gt;
   return $return;&lt;br /&gt;
}&lt;br /&gt;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Thanks Cam just what I was looking for.</p>
<p>Here’s another handy function using fgetcsv() which returns an associative array - Thanks to Donovan Bray on php.net:<br />
<code><br />
/**<br />
 * Based on an example by ramdac at ramdac dot org<br />
 * Returns a multi-dimensional array from a CSV file optionally using the<br />
 * first row as a header to create the underlying data as associative arrays.<br />
 * @param string $file Filepath including filename<br />
 * @param bool $head Use first row as header.<br />
 * @param string $delim Specify a delimiter other than a comma.<br />
 * @param int $len Line length to be passed to fgetcsv<br />
 * @return array or false on failure to retrieve any rows.<br />
 */<br />
function importcsv($file,$head=false,$delim=&quot;,&quot;,$len=1000) {<br />
   $return = false;<br />
   $handle = fopen($file, &quot;r&quot;);<br />
   if ($head) {<br />
       $header = fgetcsv($handle, $len, $delim);<br />
   }<br />
   while (($data = fgetcsv($handle, $len, $delim)) !== FALSE) {<br />
       if ($head AND isset($header)) {<br />
           foreach ($header as $key=&gt;$heading) {<br />
               $row[$heading]=(isset($data[$key])) ? $data[$key] : &#039;&#039;;<br />
           }<br />
           $return[]=$row;<br />
       } else {<br />
           $return[]=$data;<br />
       }<br />
   }<br />
   fclose($handle);<br />
   return $return;<br />
}<br />
</code>
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
