Mystery of line break character in php file writes

Posted on

‘\n’ in single quotes is a literal \n. So you won’t see line breaks when you put \n within single quotes

file_put_contents(‘log.txt’, TEST\nTEST, FILE_APPEND);
Result in log.txt file :

“\n” in double quotes is interpreted as a line break. You will see the line breaks when you put \n within double quotes
file_put_contents(‘log.txt’, TEST\nTEST, FILE_APPEND);
Result in log.txt file :


For more info:

Thankx for reading. Cheers!!!


Sql query to search for a value in csv field

Posted on Updated on

Sql query to search for a value in csv field

Magento Version
$collection->addAttributeToFilter(‘FIELD_NAME’, array(‘regexp’=> ”(\,VALUE\,)|(^VALUE\,)|(\,VALUE$)’));


Table ‘test’
id |value                        |
1  |1,2,3,4,5,6                |
2  |2,4,11,12                  |

Search for a row which has a value of 1 in the csv in value column

SQL Query
SELECT * FROM ‘test’ WHERE `value` REGEXP ‘(\,1\,)|(^1\,)|(\,1$)’

List of Countries and Country Codes

Posted on Updated on

List of Countries and Countries Codes


AF AFG Afghanistan
AL ALB Albania, People’s Socialist
Republic of
DZ DZA Algeria, People’s Democratic
Republic of
AS ASM American Samoa
AD AND Andorra, Principality of
AO AGO Angola, Republic of
AI AIA Anguilla
AQ ATA Antarctica (the territory South
of 60 deg S)
AG ATG Antigua and Barbuda
AR ARG Argentina, Argentine Republic
AM ARM Armenia
AW ABW Aruba
AU AUS Australia, Commonwealth of
AT AUT Austria, Republic of
AZ AZE Azerbaijan, Republic of
BS BHS Bahamas, Commonwealth of the
BH BHR Bahrain, Kingdom of
BD BGD Bangladesh, People’s Republic of
BB BRB Barbados
BY BLR Belarus
BE BEL Belgium, Kingdom of
BZ BLZ Belize
BJ BEN Benin (was Dahomey), People’s
Republic of
BM BMU Bermuda
BT BTN Bhutan, Kingdom of
BO BOL Bolivia, Republic of
BA BIH Bosnia and Herzegovina
BW BWA Botswana, Republic of
BV BVT Bouvet Island (Bouvetoya)
BR BRA Brazil, Federative Republic of
IO IOT British Indian Ocean Territory
(Chagos Archipelago)
VG VGB British Virgin Islands
BN BRN Brunei Darussalam
BG BGR Bulgaria, People’s Republic of
BF BFA Burkina Faso (was Upper Volta)
BI BDI Burundi, Republic of
KH KHM Cambodia, Kingdom of (was Khmer
Republic/Kampuchea, Democratic)
CM CMR Cameroon, United Republic of
CA CAN Canada
CV CPV Cape Verde, Republic of
KY CYM Cayman Islands
CF CAF Central African Republic
TD TCD Chad, Republic of
CL CHL Chile, Republic of
CN CHN China, People’s Republic of
CX CXR Christmas Island
CC CCK Cocos (Keeling) Islands
CO COL Colombia, Republic of
KM COM Comoros, Union of the
CD COD Congo, Democratic Republic of
(was Zaire)
CG COG Congo, People’s Republic of
CK COK Cook Islands
CR CRI Costa Rica, Republic of
CI CIV Cote D’Ivoire, Ivory Coast,
Republic of the
CU CUB Cuba, Republic of
CY CYP Cyprus, Republic of
CZ CZE Czech Republic
DK DNK Denmark, Kingdom of
DJ DJI Djibouti, Republic of (was
French Afars and Issas)
DM DMA Dominica, Commonwealth of
DO DOM Dominican Republic
EC ECU Ecuador, Republic of
EG EGY Egypt, Arab Republic of
SV SLV El Salvador, Republic of
GQ GNQ Equatorial Guinea, Republic of
ER ERI Eritrea
EE EST Estonia
ET ETH Ethiopia
FO FRO Faeroe Islands
FK FLK Falkland Islands (Malvinas)
FJ FJI Fiji, Republic of the Fiji
FI FIN Finland, Republic of
FR FRA France, French Republic
GF GUF French Guiana
PF PYF French Polynesia
TF ATF French Southern Territories
GA GAB Gabon, Gabonese Republic
GM GMB Gambia, Republic of the
GE GEO Georgia
DE DEU Germany
GH GHA Ghana, Republic of
GI GIB Gibraltar
GR GRC Greece, Hellenic Republic
GL GRL Greenland
GD GRD Grenada
GP GLP Guadaloupe
GT GTM Guatemala, Republic of
GN GIN Guinea, Revolutionary People’s
Rep’c of
GW GNB Guinea-Bissau, Republic of (was
Portuguese Guinea)
GY GUY Guyana, Republic of
HT HTI Haiti, Republic of
HM HMD Heard and McDonald Islands
VA VAT Holy See (Vatican City State)
HN HND Honduras, Republic of
HK HKG Hong Kong, Special
Administrative Region of China
HR HRV Hrvatska (Croatia)
HU HUN Hungary, Hungarian People’s
IS ISL Iceland, Republic of
IN IND India, Republic of
ID IDN Indonesia, Republic of
IR IRN Iran, Islamic Republic of
IQ IRQ Iraq, Republic of
IE IRL Ireland
IL ISR Israel, State of
IT ITA Italy, Italian Republic
JM JAM Jamaica
JP JPN Japan
JO JOR Jordan, Hashemite Kingdom of
KZ KAZ Kazakhstan, Republic of
KE KEN Kenya, Republic of
KI KIR Kiribati, Republic of (was
Gilbert Islands)
KP PRK Korea, Democratic People’s
Republic of
KR KOR Korea, Republic of
KW KWT Kuwait, State of
KG KGZ Kyrgyz Republic
LA LAO Lao People’s Democratic Republic
LV LVA Latvia
LB LBN Lebanon, Lebanese Republic
LS LSO Lesotho, Kingdom of
LR LBR Liberia, Republic of
LY LBY Libyan Arab Jamahiriya
LI LIE Liechtenstein, Principality of
LT LTU Lithuania
LU LUX Luxembourg, Grand Duchy of
MO MAC Macao, Special Administrative
Region of China
MK MKD Macedonia, the former Yugoslav
Republic of
MG MDG Madagascar, Republic of
MW MWI Malawi, Republic of
MY MYS Malaysia
MV MDV Maldives, Republic of
ML MLI Mali, Republic of
MT MLT Malta, Republic of
MH MHL Marshall Islands
MQ MTQ Martinique
MR MRT Mauritania, Islamic Republic of
MU MUS Mauritius
YT MYT Mayotte
MX MEX Mexico, United Mexican States
FM FSM Micronesia, Federated States of
MD MDA Moldova, Republic of
MC MCO Monaco, Principality of
MN MNG Mongolia, Mongolian People’s
MS MSR Montserrat
MA MAR Morocco, Kingdom of
MZ MOZ Mozambique, People’s Republic of
MM MMR Myanmar (was Burma)
NA NAM Namibia
NR NRU Nauru, Republic of
NP NPL Nepal, Kingdom of
AN ANT Netherlands Antilles
NL NLD Netherlands, Kingdom of the
NC NCL New Caledonia
NZ NZL New Zealand
NI NIC Nicaragua, Republic of
NE NER Niger, Republic of the
NG NGA Nigeria, Federal Republic of
NU NIU Niue, Republic of
NF NFK Norfolk Island
MP MNP Northern Mariana Islands
NO NOR Norway, Kingdom of
OM OMN Oman, Sultanate of (was Muscat
and Oman)
PK PAK Pakistan, Islamic Republic of
PW PLW Palau
PS PSE Palestinian Territory, Occupied
PA PAN Panama, Republic of
PG PNG Papua New Guinea
PY PRY Paraguay, Republic of
PE PER Peru, Republic of
PH PHL Philippines, Republic of the
PN PCN Pitcairn Island
PL POL Poland, Polish People’s Republic
PT PRT Portugal, Portuguese Republic
PR PRI Puerto Rico
QA QAT Qatar, State of
RE REU Reunion
RO ROU Romania, Socialist Republic of
RU RUS Russian Federation
RW RWA Rwanda, Rwandese Republic
SH SHN St. Helena
KN KNA St. Kitts and Nevis
LC LCA St. Lucia
PM SPM St. Pierre and Miquelon
VC VCT St. Vincent and the Grenadines
WS WSM Samoa, Independent State of (was
Western Samoa)
SM SMR San Marino, Republic of
ST STP Sao Tome and Principe,
Democratic Republic of
SA SAU Saudi Arabia, Kingdom of
SN SEN Senegal, Republic of
CS SCG Serbia and Montenegro
SC SYC Seychelles, Republic of
SL SLE Sierra Leone, Republic of
SG SGP Singapore, Republic of
SK SVK Slovakia (Slovak Republic)
SI SVN Slovenia
SB SLB Solomon Islands (was British
Solomon Islands)
SO SOM Somalia, Somali Republic
ZA ZAF South Africa, Republic of
GS SGS South Georgia and the South
Sandwich Islands
ES ESP Spain, Spanish State
LK LKA Sri Lanka, Democratic Socialist
Republic of (was Ceylon)
SD SDN Sudan, Democratic Republic of
SR SUR Suriname, Republic of
SJ SJM Svalbard & Jan Mayen Islands
SZ SWZ Swaziland, Kingdom of
SE SWE Sweden, Kingdom of
CH CHE Switzerland, Swiss Confederation
SY SYR Syrian Arab Republic
TW TWN Taiwan, Province of China
TJ TJK Tajikistan
TZ TZA Tanzania, United Republic of
TH THA Thailand, Kingdom of
TL TLS Timor-Leste, Democratic Republic
TG TGO Togo, Togolese Republic
TK TKL Tokelau (Tokelau Islands)
TO TON Tonga, Kingdom of
TT TTO Trinidad and Tobago, Republic of
TN TUN Tunisia, Republic of
TR TUR Turkey, Republic of
TM TKM Turkmenistan
TC TCA Turks and Caicos Islands
TV TUV Tuvalu (was part of Gilbert
& Ellice Islands)
VI VIR US Virgin Islands
UG UGA Uganda, Republic of
UA UKR Ukraine
AE ARE United Arab Emirates (was
Trucial States)
GB GBR United Kingdom of Great Britain
& N. Ireland
UM UMI United States Minor Outlying
US USA United States of America
UY URY Uruguay, Eastern Republic of
UZ UZB Uzbekistan
VU VUT Vanuatu (was New Hebrides)
VE VEN Venezuela, Bolivarian Republic
VN VNM Viet Nam, Socialist Republic of
(was Democratic Republic of & Republic of)
WF WLF Wallis and Futuna Islands
EH ESH Western Sahara (was Spanish
YE YEM Yemen
ZM ZMB Zambia, Republic of
ZW ZWE Zimbabwe (was Southern Rhodesia)

Grab images in Bulk from url using php and CURL

Posted on Updated on

Here is a simple php script to grab and store images from image URL using CURL.
In this example I have a list of images in an excel formatted xml file which has a field of the images link. we are using the image links to grab it.

function GetImageFromUrl($link){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return $result;
if (file_exists('images.xml')) {
$xml = simplexml_load_file('images.xml');
foreach($xml->Worksheet->Table->Row as $ab){
$file = $ab->Cell->Data;
$ch = curl_init($file);
if($file==" "){
$file = str_replace(" ","_",$file);//replace spaces from file with an underscore
$pos = strrpos($file,'/');
$filename = str_split($file,$pos+1);
$savefile = fopen('test/'.$filename[1], 'w');
fwrite($savefile, $sourcecode);
echo($filename." has been uploaded");
} else {
exit('Failed to open xml file.');