On Wed, Mar 13, 2002 at 01:45:21PM +0100, Andy wrote:
> 
> How could I generate a php script which scannes the dir for matching
> Countrycode patterns and renames the filename ?
> E.g.: Make out of CA-map.gif -> canada-map.gif?

First, make an array of countries codes and names (see below for one I 
created for you).  Second, loop through each file in the directory.  
Third, do a preg_replace() which grabs the existing country code out of 
the name and replaces it with the value of the corresponding array.  
Fourth, rename the file with the new name.

Untested example of the Third step (assuming the array has already been 
created before going into the while loop of the directory listing):

   $New = preg_replace('/^(\w\w)(-map\.gif)$/i',
            "$Countries[\\1]\\2", $FileName);


The array with Country Codes as the key and the Country Name as the 
value (put this before the other steps):

$Countries['AF'] = 'Afghanistan';
$Countries['AL'] = 'Albania';
$Countries['DZ'] = 'Algeria';
$Countries['AS'] = 'American Samoa';
$Countries['AD'] = 'Andorra';
$Countries['AO'] = 'Angola';
$Countries['AI'] = 'Anguilla';
$Countries['AQ'] = 'Antarctica';
$Countries['AG'] = 'Antigua and Barbuda';
$Countries['AR'] = 'Argentina';
$Countries['AM'] = 'Armenia';
$Countries['AW'] = 'Aruba';
$Countries['AU'] = 'Australia';
$Countries['AT'] = 'Austria';
$Countries['AZ'] = 'Azerbaijan';
$Countries['BS'] = 'Bahamas';
$Countries['BH'] = 'Bahrain';
$Countries['BD'] = 'Bangladesh';
$Countries['BB'] = 'Barbados';
$Countries['BY'] = 'Belarus';
$Countries['BE'] = 'Belgium';
$Countries['BZ'] = 'Belize';
$Countries['BJ'] = 'Benin';
$Countries['BM'] = 'Bermuda';
$Countries['BT'] = 'Bhutan';
$Countries['BO'] = 'Bolivia';
$Countries['BA'] = 'Bosnia and Herzegovina';
$Countries['BW'] = 'Botswana';
$Countries['BV'] = 'Bouvet Island';
$Countries['BR'] = 'Brazil';
$Countries['IO'] = 'British Indian Ocean Territory';
$Countries['BN'] = 'Brunei';
$Countries['BG'] = 'Bulgaria';
$Countries['BF'] = 'Burkina Faso';
$Countries['BI'] = 'Burundi';
$Countries['KH'] = 'Cambodia';
$Countries['CM'] = 'Cameroon';
$Countries['CA'] = 'Canada';
$Countries['CV'] = 'Cape Verde';
$Countries['KY'] = 'Cayman Islands';
$Countries['CF'] = 'Central African Republic';
$Countries['TD'] = 'Chad';
$Countries['CL'] = 'Chile';
$Countries['CN'] = 'China';
$Countries['CX'] = 'Christmas Island';
$Countries['CC'] = 'Cocos (Keeling) Islands';
$Countries['CO'] = 'Colombia';
$Countries['KM'] = 'Comoros';
$Countries['ZR'] = 'Congo, Democratic Republic of the';
$Countries['CG'] = 'Congo, Republic of the';
$Countries['CK'] = 'Cook Islands';
$Countries['CR'] = 'Costa Rica';
$Countries['CI'] = 'Cote dIvoire';
$Countries['HR'] = 'Croatia';
$Countries['CU'] = 'Cuba';
$Countries['CY'] = 'Cyprus';
$Countries['CZ'] = 'Czech Republic';
$Countries['DK'] = 'Denmark';
$Countries['DJ'] = 'Djibouti';
$Countries['DM'] = 'Dominica';
$Countries['DO'] = 'Dominican Republic';
$Countries['TP'] = 'East Timor';
$Countries['EC'] = 'Ecuador';
$Countries['EG'] = 'Egypt';
$Countries['SV'] = 'El Salvador';
$Countries['GQ'] = 'Equatorial Guinea';
$Countries['ER'] = 'Eritrea';
$Countries['EE'] = 'Estonia';
$Countries['ET'] = 'Ethiopia';
$Countries['FK'] = 'Falkland Islands (Islas Malvinas)';
$Countries['FO'] = 'Faroe Islands';
$Countries['FJ'] = 'Fiji';
$Countries['FI'] = 'Finland';
$Countries['FR'] = 'France';
$Countries['GF'] = 'French Guiana';
$Countries['PF'] = 'French Polynesia';
$Countries['TF'] = 'French Southern and Antarctic Lands';
$Countries['GA'] = 'Gabon';
$Countries['GM'] = 'Gambia';
$Countries['GE'] = 'Georgia';
$Countries['DE'] = 'Germany';
$Countries['GH'] = 'Ghana';
$Countries['GI'] = 'Gibraltar';
$Countries['GR'] = 'Greece';
$Countries['GL'] = 'Greenland';
$Countries['GD'] = 'Grenada';
$Countries['GP'] = 'Guadeloupe';
$Countries['GU'] = 'Guam';
$Countries['GT'] = 'Guatemala';
$Countries['GN'] = 'Guinea';
$Countries['GW'] = 'Guinea-Bissau';
$Countries['GY'] = 'Guyana';
$Countries['HT'] = 'Haiti';
$Countries['HM'] = 'Heard Island and McDonald Islands';
$Countries['VA'] = 'Holy See (Vatican City)';
$Countries['HN'] = 'Honduras';
$Countries['HK'] = 'Hong Kong';
$Countries['HU'] = 'Hungary';
$Countries['IS'] = 'Iceland';
$Countries['IN'] = 'India';
$Countries['ID'] = 'Indonesia';
$Countries['IR'] = 'Iran';
$Countries['IQ'] = 'Iraq';
$Countries['IE'] = 'Ireland';
$Countries['IL'] = 'Israel';
$Countries['IT'] = 'Italy';
$Countries['JM'] = 'Jamaica';
$Countries['JP'] = 'Japan';
$Countries['JO'] = 'Jordan';
$Countries['KZ'] = 'Kazakhstan';
$Countries['KE'] = 'Kenya';
$Countries['KI'] = 'Kiribati';
$Countries['KP'] = 'Korea, North';
$Countries['KR'] = 'Korea, South';
$Countries['KW'] = 'Kuwait';
$Countries['KG'] = 'Kyrgyzstan';
$Countries['LA'] = 'Laos';
$Countries['LV'] = 'Latvia';
$Countries['LB'] = 'Lebanon';
$Countries['LS'] = 'Lesotho';
$Countries['LR'] = 'Liberia';
$Countries['LY'] = 'Libya';
$Countries['LI'] = 'Liechtenstein';
$Countries['LT'] = 'Lithuania';
$Countries['LU'] = 'Luxembourg';
$Countries['MO'] = 'Macau';
$Countries['MK'] = 'Macedonia, The Republic of';
$Countries['MG'] = 'Madagascar';
$Countries['MW'] = 'Malawi';
$Countries['MY'] = 'Malaysia';
$Countries['MV'] = 'Maldives';
$Countries['ML'] = 'Mali';
$Countries['MT'] = 'Malta';
$Countries['MH'] = 'Marshall Islands';
$Countries['MQ'] = 'Martinique';
$Countries['MR'] = 'Mauritania';
$Countries['MU'] = 'Mauritius';
$Countries['YT'] = 'Mayotte';
$Countries['MX'] = 'Mexico';
$Countries['FM'] = 'Micronesia, Federated States of';
$Countries['MD'] = 'Moldova';
$Countries['MC'] = 'Monaco';
$Countries['MN'] = 'Mongolia';
$Countries['MS'] = 'Montserrat';
$Countries['MA'] = 'Morocco';
$Countries['MZ'] = 'Mozambique';
$Countries['MM'] = 'Myanmar (Burma)';
$Countries['NA'] = 'Namibia';
$Countries['NR'] = 'Nauru';
$Countries['NP'] = 'Nepal';
$Countries['NL'] = 'Netherlands';
$Countries['AN'] = 'Netherlands Antilles';
$Countries['NC'] = 'New Caledonia';
$Countries['NZ'] = 'New Zealand';
$Countries['NI'] = 'Nicaragua';
$Countries['NE'] = 'Niger';
$Countries['NG'] = 'Nigeria';
$Countries['NU'] = 'Niue';
$Countries['NF'] = 'Norfolk Island';
$Countries['MP'] = 'Northern Mariana Islands';
$Countries['NO'] = 'Norway';
$Countries['OM'] = 'Oman';
$Countries['PK'] = 'Pakistan';
$Countries['PW'] = 'Palau';
$Countries['PS'] = 'Palestinian Territory';
$Countries['PA'] = 'Panama';
$Countries['PG'] = 'Papua New Guinea';
$Countries['PY'] = 'Paraguay';
$Countries['PE'] = 'Peru';
$Countries['PH'] = 'Philippines';
$Countries['PN'] = 'Pitcairn Islands';
$Countries['PL'] = 'Poland';
$Countries['PT'] = 'Portugal';
$Countries['PR'] = 'Puerto Rico';
$Countries['QA'] = 'Qatar';
$Countries['RE'] = 'Reunion';
$Countries['RO'] = 'Romania';
$Countries['RU'] = 'Russia';
$Countries['RW'] = 'Rwanda';
$Countries['SH'] = 'Saint Helena';
$Countries['KN'] = 'Saint Kitts and Nevis';
$Countries['LC'] = 'Saint Lucia';
$Countries['PM'] = 'Saint Pierre and Miquelon';
$Countries['VC'] = 'Saint Vincent and the Grenadines';
$Countries['WS'] = 'Samoa';
$Countries['SM'] = 'San Marino';
$Countries['ST'] = 'Sao Tome and Principe';
$Countries['SA'] = 'Saudi Arabia';
$Countries['SN'] = 'Senegal';
$Countries['SC'] = 'Seychelles';
$Countries['SL'] = 'Sierra Leone';
$Countries['SG'] = 'Singapore';
$Countries['SK'] = 'Slovakia';
$Countries['SI'] = 'Slovenia';
$Countries['SB'] = 'Solomon Islands';
$Countries['SO'] = 'Somalia';
$Countries['ZA'] = 'South Africa';
$Countries['GS'] = 'South Georgia and the South Sandwich Islands';
$Countries['ES'] = 'Spain';
$Countries['LK'] = 'Sri Lanka';
$Countries['SD'] = 'Sudan';
$Countries['SR'] = 'Suriname';
$Countries['SJ'] = 'Svalbard';
$Countries['SZ'] = 'Swaziland';
$Countries['SE'] = 'Sweden';
$Countries['CH'] = 'Switzerland';
$Countries['SY'] = 'Syria';
$Countries['TW'] = 'Taiwan';
$Countries['TJ'] = 'Tajikistan';
$Countries['TZ'] = 'Tanzania';
$Countries['TH'] = 'Thailand';
$Countries['TG'] = 'Togo';
$Countries['TK'] = 'Tokelau';
$Countries['TO'] = 'Tonga';
$Countries['TT'] = 'Trinidad and Tobago';
$Countries['TN'] = 'Tunisia';
$Countries['TR'] = 'Turkey';
$Countries['TM'] = 'Turkmenistan';
$Countries['TC'] = 'Turks and Caicos Islands';
$Countries['TV'] = 'Tuvalu';
$Countries['UG'] = 'Uganda';
$Countries['UA'] = 'Ukraine';
$Countries['AE'] = 'United Arab Emirates';
$Countries['GB'] = 'United Kingdom';
$Countries['US'] = 'United States';
$Countries['UM'] = 'United States Minor Outlying Islands';
$Countries['UY'] = 'Uruguay';
$Countries['UZ'] = 'Uzbekistan';
$Countries['VU'] = 'Vanuatu';
$Countries['VE'] = 'Venezuela';
$Countries['VN'] = 'Vietnam';
$Countries['VG'] = 'Virgin Islands (British)';
$Countries['VI'] = 'Virgin Islands (US)';
$Countries['WF'] = 'Wallis and Futuna';
$Countries['EH'] = 'Western Sahara';
$Countries['YE'] = 'Yemen';
$Countries['YU'] = 'Yugoslavia';
$Countries['ZM'] = 'Zambia';
$Countries['ZW'] = 'Zimbabwe';

--
                PHP scripts that make your job easier
              http://www.analysisandsolutions.com/code/
         SQL Solution  |  Layout Solution  |  Form Solution
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to