function regions_api_csv_import_regions in Country codes API 6
Function to import regions from CSV file TODO: provide arguments for specifying csv files TODO: Setup permissions
Parameters
$offset: Int value for csv row offset.
1 call to regions_api_csv_import_regions()
- regions_api_install in contrib/
regions_api/ regions_api.install - Implementation of hook_install().
File
- contrib/
regions_api/ regions_api.module, line 67 - Regions API provides an API for accessing country region (province/state) data.
Code
function regions_api_csv_import_regions($offset = 1) {
//Prepopulate regions table
$handle = fopen(dirname(__FILE__) . "/data/regions.csv", "r");
$index = 1;
while (($row = fgetcsv($handle, 1024, ",")) !== FALSE) {
//Create row variables
$iso2 = isset($row[0]) ? $row[0] : "";
$name = isset($row[1]) ? $row[1] : "";
$abbreviation = isset($row[2]) ? $row[2] : "";
if ($index > $offset) {
db_query("INSERT INTO {regions_api_regions} (iso2, name, abbreviation) VALUES('%s', '%s', '%s')", $iso2, $name, $abbreviation);
}
$index++;
}
fclose($handle);
watchdog('regions_api', "Pre-populated regions data.");
}