note 97630 modified in function.fgetcsv by danbrown

From: Date: Thu, 29 Apr 2010 14:49:38 +0000
Subject: note 97630 modified in function.fgetcsv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168790@lists.php.net to get a copy of this message
If you want to load some translations for your application, don't use csv files for that, even if it's easier to handle. The following code snippet: <?php $lang = array(); $handle = fopen('en.csv', 'r'); while($row = fgetcsv($handle, 500, ';')) { $lang[$row[0]] = $row[1]; } fclose($handle); ?> is about 400% slower than this code: <?php $lang = array(); $values = parse_ini_file('de.ini'); foreach($values as $key => $val) { $lang[$key] = $val; } ?> That's the reason why you should allways use .ini files for translations... http://php.net/parse_ini_file --was-- If you want to load some translations for your application, don't use csv files for that, even if it's easier to handle. The following code snippet: <?php $lang = array(); $handle = fopen('en.csv', 'r'); while($row = fgetcsv($handle, 500, ';')) { $lang[$row[0]] = $row[1]; } fclose($handle); ?> is about 400% slower than this code: <?php $lang = array(); $values = parse_ini_file('de.ini'); foreach($values as $key => $val) { $lang[$key] = $val; } ?> That's the reason why you should allways use .ini files for translations... http://ch2.php.net/manual/en/function.parse-ini-file.php http://php.net/manual/en/function.fgetcsv.php

« previous php.notes (#168790) next »