網頁

2014年8月25日 星期一

Wordpress開發筆記-使用 $wpdb->update 如何知道是沒有更新任何東西還是更新Fail

使用wordpress的wpdb function時,總有個小疑慮,我怎知道目前的update是成功還失敗,因為若因為值相同,所以沒有update,會傳回false,失敗一樣傳回false,查半天才知道,前者是傳回0,後者是真的傳回false,但一般比較都認為相同,所以要用底下這樣寫法比對,才會比對型態的不同,使用$wpdb->update時可以像以下的方式,這邊用pseudo code表示

$suc = $wpdb->update(table_name,
    array( 
 'column1' => 'value1', // string
 'column2' => 'value2'  // integer (number) 
    ), 
    array( 'ID' => 1 ), 
        array( 
     '%s',  // value1
     '%d'   // value2
    ), 
    array( '%d' )
);
if( $suc === false ) {
    //Do something about fail
}
else if( $suc === 0 ){
    //Do something about nothing update
}


參考網址:
$wpdb - what does it return on fail?

Mac學習筆記-2010中Mac Mini換上新SSD硬碟

最近試著要將舊的Mac mini重生,目前mini都是用4500轉的硬碟,實在有夠慢,就心生去買了一顆SSD硬碟想換掉,查了半天資料,買了這顆美光Micron Crucial MX100 512GB SATAⅢ固態硬碟7mm

大致步驟如下
  1. 找出Mac mini的年代及可支援的ssd再去買
  2. 確認安裝的作業系統,OS X Mavericks是免費的了,我個人是用這個
  3. 備份原本資料(我個人是沒有 )
  4. 換硬碟
  5. 安裝OS X Mavericks
  6. 開啟trim功能
前三個步驟就看個人選擇,我直接記錄第4步驟

Step 4: 換硬碟的影片



這步驟需要的工具,我是用《JACKLY》36合1螺絲起子組(維修3C商品必備),該有的都有了,但是在推出機板的動作,因為要兩根細長的鐵棍來推出機板,如下圖,記得要準備好,不然推不出來無法取出硬碟,它又卡很緊非得這樣用力頂出來。


Step 5: 安裝OS X Mavericks

我在這步驟卡很久,一直在思考是要怎樣能Clone整顆硬碟,包含Recovery HD那部分,看了不少文章,在準備的過程中,本以為是用OS X:關於「回復磁碟輔助程式」來做出一個可重安裝重開機的硬碟,看了How to speed up an aging MacBook with a solid state drive才發現,又以為應該是要用Carbon Copy Cloner將整顆硬碟備份才是,其實如Mac Lion 系統修復的幾種方式所述都不用的,不過還是有些小步驟要注意,底下是我的做法:

將卸下來的硬碟裝用外接盒,當開機用的硬碟,接上Mac mini,沒有外接盒的,就要記得做開機usb,可以用官方的OS X:關於「回復磁碟輔助程式」下載來做一個Lion版的,或參考吉米教你製作OS X Mavericks 10.9的開機安裝碟可以做一個Mavericks的開機碟。

開機時按住OPTION鍵,選擇10.9.4進入Recovery工具,或按COMMAND鍵+R,直接進入Recovery工具。

先開磁碟工具程式,選擇新硬碟,這邊要注意的是,我之前都只選清除那個tab,再按清除按鈕直接格式化,安裝到一半都會失敗,所以要做的是,選分額那個tab,再分額區分額成一個後,按“選項”確認是否為“GUID磁碟分割區表格”,格式為“Mac OS擴充格式(日誌式)”,再按套用即可。

格式化完後,關閉磁碟工具程式,選擇“重新安裝Mavericks”,再來就等安裝好了。會自動安裝開機及Recovery HD區,有安裝成功一次後,就不再需要原硬碟或USB開機碟了。

PS. 過程中有幾次下載到一半就停止了,看起來Apple那邊Server下載的狀況不是太好,失敗了就再試就好。

Step 6: 開啟Trim功能

換上後本以為不用再注意這功能,但卻發現似乎有兩種狀況:
  1. 使用程式時會突然一頓一頓的
  2. 機器非常燙
第二種狀況在猜測是重裝及環境的關係,放著一小段時間就好了,第一種狀況是蠻介意的,照著How to Check and Enable TRIM on a Mac SSD所提,看看Trim功能有沒有打開,打開“系統資訊”->“SATA/SATA Express”,如下圖,果然是沒有

看半天主要是Apple只會將自身認可的SSD硬碟預設開啟,我這顆自然不在其認可範圍,所以要動點手腳。或用第三方軟體,但我個人比較不喜歡。

查了看來用return1 / trim_enabler.sh所提供的sh即可,看了How to Check and Enable TRIM on a Mac SSDSSD Upgrade on a Mid 2010 iMac的shell script中的perl這段都不符合Mavericks的使用,都無法成功。這邊將script記錄一下

1. 備份
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original

2. 取代掉Apple辨識碼(From return1 / trim_enabler.sh
# for Yosemite, Mavericks 10.9.5 and 10.9.4 (thanks Tobi)
sudo perl -pi -e 's|(^\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

# for Mavericks 10.9.4 (thanks Tobi)
sudo perl -pi -e 's|(^\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

======Upadte for Yosemite Only======
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original
# For Yosemite you have to disable driver signature check 
sudo nvram boot-args="kext-dev-mode=1"
sudo shutdown -r now
# for Yosemite, Mavericks 10.9.5 and 10.9.4 (thanks Tobi)
sudo perl -pi -e 's|(^\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# !for Yosemite only! rebuild kext cache manually (could take a while)
sudo kextcache -m /System/Library/Caches/com.apple.kext.caches/Startup/Extensions.mkext /System/Library/Extensions
sudo touch /System/Library/Extensions/
sudo shutdown -r now

======Upadte for Yosemite 10.10.3 ======
資料截自:return1 / trim_enabler.txt
# backup patched file
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original
 
# Important: Add "kext-dev-mode=1" as Kernel Arguments or the computer won't boot.
sudo nvram boot-args="kext-dev-mode=1"
sudo shutdown -r now
 
# looks for "Apple" string in HD kext, changes it to a wildcard match for anything
sudo perl -pi -e 's|\x00\x41\x50\x50\x4c\x45\x20\x53\x53\x44\x00|\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
 
# rebuild kext cache manually (could take a while)
sudo touch /System/Library/Extensions
sudo kextcache -m /System/Library/Caches/com.apple.kext.caches/Startup/Extensions.mkext /System/Library/Extensions
 
# now reboot!
sudo shutdown -r now


3. Refresh
sudo touch /System/Library/Extensions/

4. 重開機,重開完後再打開“系統資訊”->“SATA/SATA Express”,看看是否如下圖

5. 若沒有成功,記得將備份再copy回去,重新找其他解決。若成功了也要記得重灌作業系統時要重新再做一次

看了How to Check and Enable TRIM on a Mac SSDSSD Upgrade on a Mid 2010 iMac的動作中有講“Clear the ktext caches”,我個人試了後反而有Warning出現,不知道是否動作有錯,但第三次重裝時,我沒做這動作依然可以正常,就再看看後續使用了,這邊做一下記錄
sudo kextcache -system-prelinked-kernel
sudo kextcache -system-caches

這樣就大功告成啦!!!哈哈哈

參考網址:
(Mac Mini mid-2011) Installing an SSD drive as a replacement of the HDD
Mac Lion 系統修復的幾種方式
Carbon Copy Cloner site
How to speed up an aging MacBook with a solid state drive
Carbon Copy Cloner整顆備份你的硬碟
OS X:關於「回復磁碟輔助程式」
OS X 恢復磁碟輔助程式-下載

How to Check and Enable TRIM on a Mac SSD
SSD Upgrade on a Mid 2010 iMac
return1 / trim_enabler.sh
CAUTION! SSD Drives and Yosemite

直接安裝:[MAC]自製《Mac OSX 10.9 Mavericks》專屬USB系統安裝碟
吉米教你製作OS X Mavericks 10.9的開機安裝碟

2014年8月1日 星期五

PHP學習筆記-世上所有國家列表

最近正好寫php案子時有需要,查了一下,發現不少熱心的網友做好了,可以直接用,這邊將他們列出做點記錄,免得要用時,網頁蒸發了


$country_list = array(
  "Afghanistan",
  "Albania",
  "Algeria",
  "Andorra",
  "Angola",
  "Antigua and Barbuda",
  "Argentina",
  "Armenia",
  "Australia",
  "Austria",
  "Azerbaijan",
  "Bahamas",
  "Bahrain",
  "Bangladesh",
  "Barbados",
  "Belarus",
  "Belgium",
  "Belize",
  "Benin",
  "Bhutan",
  "Bolivia",
  "Bosnia and Herzegovina",
  "Botswana",
  "Brazil",
  "Brunei",
  "Bulgaria",
  "Burkina Faso",
  "Burundi",
  "Cambodia",
  "Cameroon",
  "Canada",
  "Cape Verde",
  "Central African Republic",
  "Chad",
  "Chile",
  "China",
  "Colombi",
  "Comoros",
  "Congo (Brazzaville)",
  "Congo",
  "Costa Rica",
  "Cote d'Ivoire",
  "Croatia",
  "Cuba",
  "Cyprus",
  "Czech Republic",
  "Denmark",
  "Djibouti",
  "Dominica",
  "Dominican Republic",
  "East Timor (Timor Timur)",
  "Ecuador",
  "Egypt",
  "El Salvador",
  "Equatorial Guinea",
  "Eritrea",
  "Estonia",
  "Ethiopia",
  "Fiji",
  "Finland",
  "France",
  "Gabon",
  "Gambia, The",
  "Georgia",
  "Germany",
  "Ghana",
  "Greece",
  "Grenada",
  "Guatemala",
  "Guinea",
  "Guinea-Bissau",
  "Guyana",
  "Haiti",
  "Honduras",
  "Hungary",
  "Iceland",
  "India",
  "Indonesia",
  "Iran",
  "Iraq",
  "Ireland",
  "Israel",
  "Italy",
  "Jamaica",
  "Japan",
  "Jordan",
  "Kazakhstan",
  "Kenya",
  "Kiribati",
  "Korea, North",
  "Korea, South",
  "Kuwait",
  "Kyrgyzstan",
  "Laos",
  "Latvia",
  "Lebanon",
  "Lesotho",
  "Liberia",
  "Libya",
  "Liechtenstein",
  "Lithuania",
  "Luxembourg",
  "Macedonia",
  "Madagascar",
  "Malawi",
  "Malaysia",
  "Maldives",
  "Mali",
  "Malta",
  "Marshall Islands",
  "Mauritania",
  "Mauritius",
  "Mexico",
  "Micronesia",
  "Moldova",
  "Monaco",
  "Mongolia",
  "Morocco",
  "Mozambique",
  "Myanmar",
  "Namibia",
  "Nauru",
  "Nepal",
  "Netherlands",
  "New Zealand",
  "Nicaragua",
  "Niger",
  "Nigeria",
  "Norway",
  "Oman",
  "Pakistan",
  "Palau",
  "Panama",
  "Papua New Guinea",
  "Paraguay",
  "Peru",
  "Philippines",
  "Poland",
  "Portugal",
  "Qatar",
  "Romania",
  "Russia",
  "Rwanda",
  "Saint Kitts and Nevis",
  "Saint Lucia",
  "Saint Vincent",
  "Samoa",
  "San Marino",
  "Sao Tome and Principe",
  "Saudi Arabia",
  "Senegal",
  "Serbia and Montenegro",
  "Seychelles",
  "Sierra Leone",
  "Singapore",
  "Slovakia",
  "Slovenia",
  "Solomon Islands",
  "Somalia",
  "South Africa",
  "Spain",
  "Sri Lanka",
  "Sudan",
  "Suriname",
  "Swaziland",
  "Sweden",
  "Switzerland",
  "Syria",
  "Taiwan",
  "Tajikistan",
  "Tanzania",
  "Thailand",
  "Togo",
  "Tonga",
  "Trinidad and Tobago",
  "Tunisia",
  "Turkey",
  "Turkmenistan",
  "Tuvalu",
  "Uganda",
  "Ukraine",
  "United Arab Emirates",
  "United Kingdom",
  "United States",
  "Uruguay",
  "Uzbekistan",
  "Vanuatu",
  "Vatican City",
  "Venezuela",
  "Vietnam",
  "Yemen",
  "Zambia",
  "Zimbabwe"
 );
With Country Code
$country_list = array(
    'Afghanistan' => '93',
    'Albania' => '355',
    'Algeria' => '213',
    'American Samoa' => '1 684',
    'Andorra' => '376',
    'Angola' => '244',
    'Anguilla' => '1264',
    'Antarctica' => '672',
    'Antigua and Barbuda' => '1268',
    'Antilles, Netherlands' => '599',
    'Argentina' => '54',
    'Armenia' => '374',
    'Aruba' => '297',
    'Australia' => '61',
    'Austria' => '43',
    'Azerbaijan' => '994',
    'Bahamas' => '1242',
    'Bahrain' => '973',
    'Bangladesh' => '880',
    'Barbados' => '1246',
    'Belarus' => '375',
    'Belgium' => '375',
    'Belize' => '501',
    'Benin' => '229',
    'Bermuda' => '1 441',
    'Bhutan' => '975',
    'Bolivia' => '591',
    'Bosnia and Herzegovina' => '387',
    'Botswana' => '267',
    'Brazil' => '55',
    'British Indian Ocean Territory' => '246',
    'British Virgin Islands' => '1 284',
    'Brunei Darussalam' => '673',
    'Bulgaria' => '359',
    'Burkina Faso' => '226',
    'Burundi' => '257',
    'Cambodia' => '855',
    'Cameroon' => '237',
    'Canada' => '1',
    'Cape Verde' => '238',
    'Cayman Islands' => '1 345',
    'Central African Republic' => '236',
    'Chad' => '235',
    'Chile' => '56',
    'China' => '86',
    'Christmas Island' => '64',
    'Cocos (Keeling) Islands' => '61',
    'Colombia' => '57',
    'Comoros' => '269',
    'Congo' => '242',
    'Cook Islands' => '682',
    'Costa Rica' => '506',
    'Cote D\'Ivoire' => '225',
    'Croatia' => '385',
    'Cuba' => '53',
    'Cyprus' => '357',
    'Czech Republic' => '420',
    'Denmark' => '45',
    'Djibouti' => '253',
    'Dominica' => '1 767',
    'Dominican Republic' => '1 809',
    'East Timor (Timor-Leste)' => '670',
    'Ecuador' => '593',
    'Egypt' => '20',
    'El Salvador' => '503',
    'Equatorial Guinea' => '240',
    'Eritrea' => '291',
    'Estonia' => '372',
    'Ethiopia' => '251',
    'Falkland Islands (Malvinas)' => '500',
    'Faroe Islands' => '298',
    'Fiji' => '679',
    'Finland' => '358',
    'France' => '33',
    'French Guiana' => '594',
    'French Polynesia' => '689',
    'Gabon' => '241',
    'Gambia, the' => '220',
    'Georgia' => '995',
    'Germany' => '49',
    'Ghana' => '233',
    'Gibraltar' => '350',
    'Greece' => '30',
    'Greenland' => '299',
    'Grenada' => '1 473',
    'Guadeloupe' => '590',
    'Guam' => '1 671',
    'Guatemala' => '502',
    'Guernsey and Alderney' => '5399',
    'Guinea' => '224',
    'Guinea-Bissau' => '245',
    'Guinea, Equatorial' => '240',
    'Guiana, French' => '594',
    'Guyana' => '592',
    'Haiti' => '509',
    'Holy See (Vatican City State)' => '379',
    'Holland' => '31',
    'Honduras' => '504',
    'Hong Kong, (China)' => '852',
    'Hungary' => '36',
    'Iceland' => '354',
    'India' => '91',
    'Indonesia' => '62',
    'Iran' => '98',
    'Iraq' => '964',
    'Ireland' => '353',
    'Isle of Man' => '44',
    'Israel' => '972',
    'Italy' => '39',
    'Jamaica' => '1 876',
    'Japan' => '81',
    'Jersey' => '44',
    'Jordan' => '962',
    'Kazakhstan' => '7',
    'Kenya' => '254',
    'Kiribati' => '686',
    'Korea(North)' => '850',
    'Korea(South)' => '82',
    'Kosovo' => '381',
    'Kuwait' => '965',
    'Kyrgyzstan' => '996',
    'Lao People\'s Democratic Republic' => '856',
    'Latvia' => '371',
    'Lebanon' => '961',
    'Lesotho' => '266',
    'Liberia' => '231',
    'Libyan Arab Jamahiriya' => '218',
    'Liechtenstein' => '423',
    'Lithuania' => '370',
    'Luxembourg' => '352',
    'Macao, (China)' => '853',
    'Macedonia, TFYR' => '389',
    'Madagascar' => '261',
    'Malawi' => '265',
    'Malaysia' => '60',
    'Maldives' => '960',
    'Mali' => '223',
    'Malta' => '356',
    'Marshall Islands' => '692',
    'Martinique' => '596',
    'Mauritania' => '222',
    'Mauritius' => '230',
    'Mayotte' => '262',
    'Mexico' => '52',
    'Micronesia' => '691',
    'Moldova' => '373',
    'Monaco' => '377',
    'Mongolia' => '976',
    'Montenegro' => '382',
    'Montserrat' => '1 664',
    'Morocco' => '212',
    'Mozambique' => '258',
    'Myanmar' => '95',
    'Namibia' => '264',
    'Nauru' => '674',
    'Nepal' => '977',
    'Netherlands' => '31',
    'Netherlands Antilles' => '599',
    'New Caledonia' => '687',
    'New Zealand' => '64',
    'Nicaragua' => '505',
    'Niger' => '227',
    'Nigeria' => '234',
    'Niue' => '683',
    'Norfolk Island' => '672',
    'Northern Mariana Islands' => '1 670',
    'Norway' => '47',
    'Oman' => '968',
    'Pakistan' => '92',
    'Palau' => '680',
    'Palestinian Territory' => '970',
    'Panama' => '507',
    'Papua New Guinea' => '675',
    'Paraguay' => '595',
    'Peru' => '51',
    'Philippines' => '63',
    'Pitcairn Island' => '872',
    'Poland' => '48',
    'Portugal' => '351',
    'Puerto Rico' => '1787',
    'Qatar' => '974',
    'Reunion' => '262',
    'Romania' => '40',
    'Russia' => '7',
    'Rwanda' => '250',
    'Sahara' => '212',
    'Saint Helena' => '290',
    'Saint Kitts and Nevis' => '1869',
    'Saint Lucia' => '1758',
    'Saint Pierre and Miquelon' => '508',
    'Saint Vincent and the Grenadines' => '1784',
    'Samoa' => '685',
    'San Marino' => '374',
    'Sao Tome and Principe' => '239',
    'Saudi Arabia' => '966',
    'Senegal' => '221',
    'Serbia' => '381',
    'Seychelles' => '248',
    'Sierra Leone' => '232',
    'Singapore' => '65',
    'Slovakia' => '421',
    'Slovenia' => '386',
    'Solomon Islands' => '677',
    'Somalia' => '252',
    'South Africa' => '27',
    'S. Georgia and S. Sandwich Is.' => '500',
    'Spain' => '34',
    'Sri Lanka (ex-Ceilan)' => '94',
    'Sudan' => '249',
    'Suriname' => '597',
    'Svalbard and Jan Mayen Islands' => '79',
    'Swaziland' => '41',
    'Sweden' => '46',
    'Switzerland' => '41',
    'Syrian Arab Republic' => '963',
    'Taiwan' => '886',
    'Tajikistan' => '992',
    'Tanzania' => '255',
    'Thailand' => '66',
    'Timor-Leste (East Timor)' => '670',
    'Togo' => '228',
    'Tokelau' => '690',
    'Tonga' => '676',
    'Trinidad and Tobago' => '1 868',
    'Tunisia' => '216',
    'Turkey' => '90',
    'Turkmenistan' => '993',
    'Turks and Caicos Islands' => '1 649',
    'Tuvalu' => '688',
    'Uganda' => '256',
    'Ukraine' => '380',
    'United Arab Emirates' => '971',
    'United Kingdom' => '44',
    'United States' => '1',
    'US Minor Outlying Islands' => '808',
    'Uruguay' => '598',
    'Uzbekistan' => '998',
    'Vanuatu' => '678',
    'Vatican City State (Holy See)' => '379',
    'Venezuela' => '58',
    'Viet Nam' => '84',
    'Virgin Islands, British' => '1284',
    'Virgin Islands, U.S.' => '1340',
    'Wallis and Futuna' => '681',
    'Western Sahara' => '212',
    'Yemen' => '967',
    'Zambia' => '260',
    'Zimbabwe' => '263',
);
有人基於上頭的資訊,做成底下的function:
/**
     * Returns array with country codes
     * @param stirng $zone Country zone, optional
     * @param stirng $code Specific country code (to get country name), optional
     * @return array Where keys are country codes and values are country names in english
     */
    function countryCodeArray($zone = 'all', $code = '')
    {
        $returnData = false;
        $country_array = array(
            'Africa' => array('DZ' => 'Algeria', 'AO' => 'Angola', 'BJ' => 'Benin', 'BW' => 'Botswana', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'CM' => 'Cameroon', 'CV' => 'Cape Verde', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'KM' => 'Comoros', 'CD' => 'Congo [DRC]', 'CG' => 'Congo [Republic]', 'DJ' => 'Djibouti', 'EG' => 'Egypt', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'ET' => 'Ethiopia', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GH' => 'Ghana', 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'CI' => 'Ivory Coast', 'KE' => 'Kenya', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libya', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'ML' => 'Mali', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'NA' => 'Namibia', 'NE' => 'Niger', 'NG' => 'Nigeria', 'RW' => 'Rwanda', 'RE' => 'Réunion', 'SH' => 'Saint Helena', 'SN' => 'Senegal', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'SD' => 'Sudan', 'SZ' => 'Swaziland', 'ST' => 'São Tomé and Pr?ncipe', 'TZ' => 'Tanzania', 'TG' => 'Togo', 'TN' => 'Tunisia', 'UG' => 'Uganda', 'EH' => 'Western Sahara', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe'),
            'Antarctica' => array('AQ' => 'Antarctica', 'BV' => 'Bouvet Island', 'TF' => 'French Southern Territories', 'HM' => 'Heard Island and McDonald Island', 'GS' => 'South Georgia and the South Sandwich Islands'),
            'Asia' => array('AF' => 'Afghanistan', 'AM' => 'Armenia', 'AZ' => 'Azerbaijan', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BT' => 'Bhutan', 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei', 'KH' => 'Cambodia', 'CN' => 'China', 'CX' => 'Christmas Island', 'CC' => 'Cocos [Keeling] Islands', 'GE' => 'Georgia', 'HK' => 'Hong Kong', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran', 'IQ' => 'Iraq', 'IL' => 'Israel', 'JP' => 'Japan', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Laos', 'LB' => 'Lebanon', 'MO' => 'Macau', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'MN' => 'Mongolia', 'MM' => 'Myanmar [Burma]', 'NP' => 'Nepal', 'KP' => 'North Korea', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PS' => 'Palestinian Territories', 'PH' => 'Philippines', 'QA' => 'Qatar', 'SA' => 'Saudi Arabia', 'SG' => 'Singapore', 'KR' => 'South Korea', 'LK' => 'Sri Lanka', 'SY' => 'Syria', 'TW' => 'Taiwan', 'TJ' => 'Tajikistan', 'TH' => 'Thailand', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'AE' => 'United Arab Emirates', 'UZ' => 'Uzbekistan', 'VN' => 'Vietnam', 'YE' => 'Yemen'),
            'Europe' => array('AL' => 'Albania', 'AD' => 'Andorra', 'AT' => 'Austria', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BA' => 'Bosnia and Herzegovina', 'BG' => 'Bulgaria', 'HR' => 'Croatia', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'EE' => 'Estonia', 'FO' => 'Faroe Islands', 'FI' => 'Finland', 'FR' => 'France', 'DE' => 'Germany', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'GG' => 'Guernsey', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IE' => 'Ireland', 'IM' => 'Isle of Man', 'IT' => 'Italy', 'JE' => 'Jersey', 'XK' => 'Kosovo', 'LV' => 'Latvia', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MK' => 'Macedonia', 'MT' => 'Malta', 'MD' => 'Moldova', 'MC' => 'Monaco', 'ME' => 'Montenegro', 'NL' => 'Netherlands', 'NO' => 'Norway', 'PL' => 'Poland', 'PT' => 'Portugal', 'RO' => 'Romania', 'RU' => 'Russia', 'SM' => 'San Marino', 'RS' => 'Serbia', 'CS' => 'Serbia and Montenegro', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'ES' => 'Spain', 'SJ' => 'Svalbard and Jan Mayen', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'UA' => 'Ukraine', 'GB' => 'United Kingdom', 'VA' => 'Vatican City', 'AX' => 'Åland Islands'),
            'North America' => array('AI' => 'Anguilla', 'AG' => 'Antigua and Barbuda', 'AW' => 'Aruba', 'BS' => 'Bahamas', 'BB' => 'Barbados', 'BZ' => 'Belize', 'BM' => 'Bermuda', 'BQ' => 'Bonaire, Saint Eustatius and Saba', 'VG' => 'British Virgin Islands', 'CA' => 'Canada', 'KY' => 'Cayman Islands', 'CR' => 'Costa Rica', 'CU' => 'Cuba', 'CW' => 'Curacao', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'SV' => 'El Salvador', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GT' => 'Guatemala', 'HT' => 'Haiti', 'HN' => 'Honduras', 'JM' => 'Jamaica', 'MQ' => 'Martinique', 'MX' => 'Mexico', 'MS' => 'Montserrat', 'AN' => 'Netherlands Antilles', 'NI' => 'Nicaragua', 'PA' => 'Panama', 'PR' => 'Puerto Rico', 'BL' => 'Saint Barthélemy', 'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint Lucia', 'MF' => 'Saint Martin', 'PM' => 'Saint Pierre and Miquelon', 'VC' => 'Saint Vincent and the Grenadines', 'SX' => 'Sint Maarten', 'TT' => 'Trinidad and Tobago', 'TC' => 'Turks and Caicos Islands', 'VI' => 'U.S. Virgin Islands', 'US' => 'United States'),
            'South America' => array('AR' => 'Argentina', 'BO' => 'Bolivia', 'BR' => 'Brazil', 'CL' => 'Chile', 'CO' => 'Colombia', 'EC' => 'Ecuador', 'FK' => 'Falkland Islands', 'GF' => 'French Guiana', 'GY' => 'Guyana', 'PY' => 'Paraguay', 'PE' => 'Peru', 'SR' => 'Suriname', 'UY' => 'Uruguay', 'VE' => 'Venezuela'),
            'Oceania' => array('AS' => 'American Samoa', 'AU' => 'Australia', 'CK' => 'Cook Islands', 'TL' => 'East Timor', 'FJ' => 'Fiji', 'PF' => 'French Polynesia', 'GU' => 'Guam', 'KI' => 'Kiribati', 'MH' => 'Marshall Islands', 'FM' => 'Micronesia', 'NR' => 'Nauru', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 'NU' => 'Niue', 'NF' => 'Norfolk Island', 'MP' => 'Northern Mariana Islands', 'PW' => 'Palau', 'PG' => 'Papua New Guinea', 'PN' => 'Pitcairn Islands', 'WS' => 'Samoa', 'SB' => 'Solomon Islands', 'TK' => 'Tokelau', 'TO' => 'Tonga', 'TV' => 'Tuvalu', 'UM' => 'U.S. Minor Outlying Islands', 'VU' => 'Vanuatu', 'WF' => 'Wallis and Futuna')
        );
        if ($zone == 'all') {
            $returnData = $country_array;
        } elseif (isset($country_array[$zone])) {
            if ($code != '') {
                if (isset($country_array[$zone][$code])) {
                    $returnData = $country_array[$zone][$code];
                }
            } else {
                $returnData = $country_array[$zone];
            }
        }
        return $returnData;
    }


也許寫個像Create your own countries list的工具倒是。

參考網址:
List of world countries in php array
Text List of All Countries in the World
Javascript - All countries of the world in an array
Create your own countries list