Convert line endings from MAC to UNIX
[php-addressbook.git] / include / import.csv.php
index 2cd271c..4a0f5c7 100644 (file)
@@ -1 +1,56 @@
-<?php\r\rrequire_once "import.del.php";\r\rclass ImportCsv extends ImportDel {\r\r  function ImportCsv( $file_lines\r                    , $delims = array(";", ",", "\t")\r                    , $quotes = array('"', "'")\r                    ) {\r                           \r    function maxChar($chars, $testString) {\r           \r       $max_count = 0;         \r      $the_char  = (count($chars) > 0 ? $chars[0] : " ");\r      foreach($chars as $char) {\r            $new_count = substr_count($testString, $char);\r         if($new_count > $max_count) {\r                  $max_count = $new_count;\r               $the_char  = $char;\r            }\r      }\r      \r      return $the_char;\r    }\r    \r    $test_line = $file_lines[0];\r    \r    //\r    // Detect the most probable delimiter.\r    //\r    $delim = maxChar($delims, $test_line);\r    $quote = maxChar($quotes, $test_line);\r    \r    //\r    // Re-Conncat the file-lines\r    //\r     $input = implode("\n", $file_lines)."\n";\r      \r    //\r        // Setup and run the parser\r    //\r    include "lib/parsecsv.lib.php";\r         $csv = new parseCSV();\r         $csv->delimiter = $delim;\r      $csv->enclosure = $quote;\r      $csv->file_data = &$input;      \r       $this->data = $csv->parse_string();\r\r    //\r    // Convert the array to addresses\r    //           \r    $this->convertToAddresses();\r  }\r}\r?>
\ No newline at end of file
+<?php
+
+require_once "import.del.php";
+
+class ImportCsv extends ImportDel {
+
+  function ImportCsv( $file_lines
+                    , $delims = array(";", ",", "\t")
+                    , $quotes = array('"', "'")
+                    ) {
+                       
+    function maxChar($chars, $testString) {
+       
+       $max_count = 0;         
+      $the_char  = (count($chars) > 0 ? $chars[0] : " ");
+      foreach($chars as $char) {
+       $new_count = substr_count($testString, $char);
+       if($new_count > $max_count) {
+               $max_count = $new_count;
+               $the_char  = $char;
+       }
+      }
+      
+      return $the_char;
+    }
+    
+    $test_line = $file_lines[0];
+    
+    //
+    // Detect the most probable delimiter.
+    //
+    $delim = maxChar($delims, $test_line);
+    $quote = maxChar($quotes, $test_line);
+    
+    //
+    // Re-Conncat the file-lines
+    //
+         $input = implode("\n", $file_lines)."\n";
+         
+    //
+         // Setup and run the parser
+    //
+    include "lib/parsecsv.lib.php";
+         $csv = new parseCSV();
+         $csv->delimiter = $delim;
+         $csv->enclosure = $quote;
+         $csv->file_data = &$input;      
+         $this->data = $csv->parse_string();
+
+    //
+    // Convert the array to addresses
+    //           
+    $this->convertToAddresses();
+  }
+}
+?>
\ No newline at end of file