Xataface 2.0
Xataface Application Framework
tools/csv2ini.php
Go to the documentation of this file.
00001 <?php
00002 
00003 $inputPath = null;
00004 $outputPath = null;
00005 $dicts = array();
00006 
00007 foreach ($argv as $arg ){
00008         if ( preg_match('/\.csv$/', $arg) ){
00009                 $inputPath = $arg;
00010                 continue;
00011         }
00012         
00013         if ( preg_match('/\.php$/', $arg )  ) continue;
00014         
00015         if ( is_dir($arg) ){
00016                 $outputPath = dirname($arg).'/';
00017         } else {
00018                 $outputPath = $arg.'.';
00019         }
00020 }
00021 
00022 if ( !isset($outputPath) ){
00023 
00024         fwrite( STDERR, "No output path was supplied.\n");
00025         exit;
00026 }
00027 
00028 
00029 if ( !isset($inputPath) ){
00030         fwrite(STDERR, "No input CSV file was specified.\n");
00031         exit;
00032 
00033 }
00034 
00035 
00036 
00037 $fp = fopen($inputPath, 'r');
00038 if ( !$fp ){
00039         fwrite(STDERR, "The Input file $inputPath could not be opened for reading.\n");
00040         exit;
00041 }
00042 
00043 $filenames = fgetcsv($fp);
00044 array_shift($filenames); // get rid of Key column.
00045 $filenames = array_map('basename', $filenames);
00046 foreach ( $filenames as $file ){
00047         $dicts[$file] = array();
00048 }
00049 
00050 while ( $row = fgetcsv($fp) ){
00051         $key = array_shift($row);
00052         foreach ( $filenames as $i=>$file ){
00053                 if ( isset($row[$i]) and !empty($row[$i]) ){
00054                         $dicts[$file][$key] = $row[$i];
00055                 }
00056         }
00057 }
00058 fclose($fp);
00059 
00060 foreach ( $dicts as $file => $contents ){
00061         
00062         $df = fopen($outputPath.$file, 'w');
00063         foreach ($contents as $key=>$val){
00064                 fwrite($df, $key.' = "'.str_replace('"', '"XATAFACEQ"', $val).'"'."\r\n");
00065                 
00066         }
00067         fclose($df);
00068 
00069 }
00070 
00071 fwrite(STDOUT, "Conversions complete.\n");
00072 
00073 
00074 
00075 
00076 
00077 
 All Data Structures Namespaces Files Functions Variables Enumerations