function continents_api_csv_import_continents in Country codes API 5
Same name and namespace in other branches
- 6 contrib/continents_api/continents_api.module \continents_api_csv_import_continents()
Function to import regions from CSV file TODO: provide arguments for specifying csv files TODO: Setup permissions
Parameters
$offset: Integer value for CSV row offset.
1 call to continents_api_csv_import_continents()
- continents_api_install in contrib/
continents_api/ continents_api.install - Implementation of hook_install().
File
- contrib/
continents_api/ continents_api.module, line 64 - Continents API provides an API for official and up-to-date list of continents and their countries. Countries are provided in ISO 3166 alpha-2 country codes. Source: http://en.wikipedia.org/wiki/List_of_countries_by_continent_(data_file)
Code
function continents_api_csv_import_continents($offset = 1) {
$handle = fopen(drupal_get_path('module', 'continents_api') . '/data/continents.csv', 'r');
$index = 1;
while (($row = fgetcsv($handle, 1024, ",")) !== FALSE) {
if ($index > $offset) {
// Create row variables.
$continent = $row[0] ? $row[0] : "";
$country = $row[1] ? $row[1] : "";
db_query("INSERT INTO {continents_api_continents} (continent, country) VALUES('%s', '%s')", $continent, $country);
}
$index++;
}
fclose($handle);
watchdog('continents_api', 'Pre-populated continents data.');
}