Skip to content

Instantly share code, notes, and snippets.

@simon-lang
Created May 30, 2011 15:04
Show Gist options
  • Select an option

  • Save simon-lang/999024 to your computer and use it in GitHub Desktop.

Select an option

Save simon-lang/999024 to your computer and use it in GitHub Desktop.
Batch replace flag names from wikipedia to iso2 codes.php
$baseDir = 'C:\wamp\www\nations\web\images\flags\replace\\';
$dir = new DirectoryIterator($baseDir);
foreach ($dir as $file) {
$name = explode('_of_', $file);
if (count($name) == 1) {
continue;
}
$name = str_replace('.svg.png', '', $name[1]);
$country = Doctrine_Core::getTable('Country')
->createQuery('a')
->andWhere('name = ?', $name)
->execute()
->getFirst();
if (is_object($country)) {
rename($baseDir.$file, $baseDir.$country->getFlag());
}
else {
unlink($baseDir.$file);
}
}
echo 'Done';
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment