transparencia Posted September 25, 2010 Share Posted September 25, 2010 This script is supposed to run in the command line. Like the title says, I need to: [*]Import some columns (input the names with an argument) from a .CSV file [*]Split the column into blocks of 500 lines [*]Translate this pieces [*]Put them back into the original file I already have some code but it is unfinished and not working: <?php //name of the .CSV file $filename = $argv[1]; //name of the column to be translated $header_name = $argv[2]; //open file $file_handle = fopen($filename, "r"); $i=0; $j=0; $counter = 0; $translated = ''; $string = ''; while (!feof($file_handle) ) { $counter++; $line_of_text = fgetcsv($file_handle, 1024); //find the column id that contains the header name. // headers are always on the the first line if ( $counter == 1 ){ while ($line_of_text[$i] != $header_name) $i++; $header_id = $i; } //create the blocks $string .= $line_of_text[$i]; if ($counter % 500 == 0) { $gt = new GoogleTranslateWrapper(); $translated .= $gt->translate($string, "en"); } } //Write the translate column in the same .CSV file fclose($file_handle); ?> Any help in rewriting this to work? Quote Link to comment Share on other sites More sharing options...
s0c0 Posted September 25, 2010 Share Posted September 25, 2010 This is not something I would've written. Instead there is a nice CSV parser class that I've used for years: http://www.phpclasses.org/package/849-PHP-Simple-CSV-parser.html Leverage other peoples code whenever possible. Let them do the debugging for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.