Sep 2, 2014

Html select box of countries with two letter ISO code

A simple html select box of countries with two letter ISO code and Country calling codes. United States of America is selected by default in following example. Change it according to your need.

If you want a list of countries for mysql database. you may visit List/database of countries for mysql

 <select name="code">
  <option value="AF">Afghanistan (+93)</option>
  <option value="AX">&Aring;land Islands (+358)</option>
  <option value="AL">Albania (+355)</option>
  <option value="DZ">Algeria (+213)</option>
  <option value="AS">American Samoa (+1)</option>
  <option value="AD">Andorra (+376)</option>
  <option value="AO">Angola (+244)</option>
  <option value="AI">Anguilla (+1)</option>
  <option value="AQ">Antarctica (+672)</option>
  <option value="AG">Antigua (+1)</option>
  <option value="AR">Argentina (+54)</option>
  <option value="AM">Armenia (+374)</option>
  <option value="AW">Aruba (+297)</option>
  <option value="AU">Australia (+61)</option>
  <option value="AT">Austria (+43)</option>
  <option value="AZ">Azerbaijan (+994)</option>
  <option value="BH">Bahrain (+973)</option>
  <option value="BD">Bangladesh (+880)</option>
  <option value="BB">Barbados (+1)</option>
  <option value="BY">Belarus (+375)</option>
  <option value="BE">Belgium (+32)</option>
  <option value="BZ">Belize (+501)</option>
  <option value="BJ">Benin (+229)</option>
  <option value="BM">Bermuda (+1)</option>
  <option value="BT">Bhutan (+975)</option>
  <option value="BO">Bolivia (+591)</option>
  <option value="BQ">Bonaire, Sint Eustatius and Saba (+599)</option>
  <option value="BA">Bosnia and Herzegovina (+387)</option>
  <option value="BW">Botswana (+267)</option>
  <option value="BR">Brazil (+55)</option>
  <option value="IO">British Indian Ocean Territory (+246)</option>
  <option value="VG">British Virgin Islands (+1)</option>
  <option value="BN">Brunei (+673)</option>
  <option value="BG">Bulgaria (+359)</option>
  <option value="BF">Burkina Faso (+226)</option>
  <option value="BI">Burundi (+257)</option>
  <option value="KH">Cambodia (+855)</option>
  <option value="CM">Cameroon (+237)</option>
  <option value="CA">Canada (+1)</option>
  <option value="CV">Cape Verde (+238)</option>
  <option value="KY">Cayman Islands (+1)</option>
  <option value="CF">Central African Republic (+236)</option>
  <option value="TD">Chad (+235)</option>
  <option value="CL">Chile (+56)</option>
  <option value="CN">China (+86)</option>
  <option value="CO">Colombia (+57)</option>
  <option value="KM">Comoros (+269)</option>
  <option value="CK">Cook Islands (+682)</option>
  <option value="CR">Costa Rica (+506)</option>
  <option value="CI">C&ocirc;te d'Ivoire (+225)</option>
  <option value="HR">Croatia (+385)</option>
  <option value="CU">Cuba (+53)</option>
  <option value="CW">Cura&ccedil;ao (+599)</option>
  <option value="CY">Cyprus (+357)</option>
  <option value="CZ">Czech Republic (+420)</option>
  <option value="CD">Democratic Republic of the Congo (+243)</option>
  <option value="DK">Denmark (+45)</option>
  <option value="DJ">Djibouti (+253)</option>
  <option value="DM">Dominica (+1)</option>
  <option value="DO">Dominican Republic (+1)</option>
  <option value="EC">Ecuador (+593)</option>
  <option value="EG">Egypt (+20)</option>
  <option value="SV">El Salvador (+503)</option>
  <option value="GQ">Equatorial Guinea (+240)</option>
  <option value="ER">Eritrea (+291)</option>
  <option value="EE">Estonia (+372)</option>
  <option value="ET">Ethiopia (+251)</option>
  <option value="FK">Falkland Islands (+500)</option>
  <option value="FO">Faroe Islands (+298)</option>
  <option value="FM">Federated States of Micronesia (+691)</option>
  <option value="FJ">Fiji (+679)</option>
  <option value="FI">Finland (+358)</option>
  <option value="FR">France (+33)</option>
  <option value="GF">French Guiana (+594)</option>
  <option value="PF">French Polynesia (+689)</option>
  <option value="GA">Gabon (+241)</option>
  <option value="GE">Georgia (+995)</option>
  <option value="DE">Germany (+49)</option>
  <option value="GH">Ghana (+233)</option>
  <option value="GI">Gibraltar (+350)</option>
  <option value="GR">Greece (+30)</option>
  <option value="GL">Greenland (+299)</option>
  <option value="GD">Grenada (+1)</option>
  <option value="GP">Guadeloupe (+590)</option>
  <option value="GU">Guam (+1)</option>
  <option value="GT">Guatemala (+502)</option>
  <option value="GN">Guinea (+224)</option>
  <option value="GW">Guinea-Bissau (+245)</option>
  <option value="GY">Guyana (+592)</option>
  <option value="HT">Haiti (+509)</option>
  <option value="HN">Honduras (+504)</option>
  <option value="HK">Hong Kong (+852)</option>
  <option value="HU">Hungary (+36)</option>
  <option value="IS">Iceland (+354)</option>
  <option value="IN">India (+91)</option>
  <option value="ID">Indonesia (+62)</option>
  <option value="IR">Iran (+98)</option>
  <option value="IQ">Iraq (+964)</option>
  <option value="IE">Ireland (+353)</option>
  <option value="IM">Isle Of Man (+44)</option>
  <option value="IL">Israel (+972)</option>
  <option value="IT">Italy (+39)</option>
  <option value="JM">Jamaica (+1)</option>
  <option value="JP">Japan (+81)</option>
  <option value="JO">Jordan (+962)</option>
  <option value="KZ">Kazakhstan (+7)</option>
  <option value="KE">Kenya (+254)</option>
  <option value="KI">Kiribati (+686)</option>
  <option value="XK">Kosovo (+381)</option>
  <option value="KW">Kuwait (+965)</option>
  <option value="KG">Kyrgyzstan (+996)</option>
  <option value="LA">Laos (+856)</option>
  <option value="LV">Latvia (+371)</option>
  <option value="LB">Lebanon (+961)</option>
  <option value="LS">Lesotho (+266)</option>
  <option value="LR">Liberia (+231)</option>
  <option value="LY">Libya (+218)</option>
  <option value="LI">Liechtenstein (+423)</option>
  <option value="LT">Lithuania (+370)</option>
  <option value="LU">Luxembourg (+352)</option>
  <option value="MO">Macau (+853)</option>
  <option value="MK">Macedonia (+389)</option>
  <option value="MG">Madagascar (+261)</option>
  <option value="MW">Malawi (+265)</option>
  <option value="MY">Malaysia (+60)</option>
  <option value="MV">Maldives (+960)</option>
  <option value="ML">Mali (+223)</option>
  <option value="MT">Malta (+356)</option>
  <option value="MH">Marshall Islands (+692)</option>
  <option value="MQ">Martinique (+596)</option>
  <option value="MR">Mauritania (+222)</option>
  <option value="MU">Mauritius (+230)</option>
  <option value="YT">Mayotte (+262)</option>
  <option value="MX">Mexico (+52)</option>
  <option value="MD">Moldova (+373)</option>
  <option value="MC">Monaco (+377)</option>
  <option value="MN">Mongolia (+976)</option>
  <option value="ME">Montenegro (+382)</option>
  <option value="MS">Montserrat (+1)</option>
  <option value="MA">Morocco (+212)</option>
  <option value="MZ">Mozambique (+258)</option>
  <option value="MM">Myanmar (+95)</option>
  <option value="NA">Namibia (+264)</option>
  <option value="NR">Nauru (+674)</option>
  <option value="NP">Nepal (+977)</option>
  <option value="NL">Netherlands (+31)</option>
  <option value="NC">New Caledonia (+687)</option>
  <option value="NZ">New Zealand (+64)</option>
  <option value="NI">Nicaragua (+505)</option>
  <option value="NE">Niger (+227)</option>
  <option value="NG">Nigeria (+234)</option>
  <option value="NU">Niue (+683)</option>
  <option value="NF">Norfolk Island (+672)</option>
  <option value="KP">North Korea (+850)</option>
  <option value="MP">Northern Mariana Islands (+1)</option>
  <option value="NO">Norway (+47)</option>
  <option value="OM">Oman (+968)</option>
  <option value="PK">Pakistan (+92)</option>
  <option value="PW">Palau (+680)</option>
  <option value="PS">Palestine (+970)</option>
  <option value="PA">Panama (+507)</option>
  <option value="PG">Papua New Guinea (+675)</option>
  <option value="PY">Paraguay (+595)</option>
  <option value="PE">Peru (+51)</option>
  <option value="PH">Philippines (+63)</option>
  <option value="PL">Poland (+48)</option>
  <option value="PT">Portugal (+351)</option>
  <option value="PR">Puerto Rico (+1)</option>
  <option value="QA">Qatar (+974)</option>
  <option value="CG">Republic of the Congo (+242)</option>
  <option value="RE">Réunion (+262)</option>
  <option value="RO">Romania (+40)</option>
  <option value="RU">Russia (+7)</option>
  <option value="RW">Rwanda (+250)</option>
  <option value="BL">Saint Barthélemy (+590)</option>
  <option value="SH">Saint Helena (+290)</option>
  <option value="KN">Saint Kitts and Nevis (+1)</option>
  <option value="MF">Saint Martin (+590)</option>
  <option value="PM">Saint Pierre and Miquelon (+508)</option>
  <option value="VC">Saint Vincent and the Grenadines (+1)</option>
  <option value="WS">Samoa (+685)</option>
  <option value="SM">San Marino (+378)</option>
  <option value="ST">Sao Tome and Principe (+239)</option>
  <option value="SA">Saudi Arabia (+966)</option>
  <option value="SN">Senegal (+221)</option>
  <option value="RS">Serbia (+381)</option>
  <option value="SC">Seychelles (+248)</option>
  <option value="SL">Sierra Leone (+232)</option>
  <option value="SG">Singapore (+65)</option>
  <option value="SX">Sint Maarten (+599)</option>
  <option value="SK">Slovakia (+421)</option>
  <option value="SI">Slovenia (+386)</option>
  <option value="SB">Solomon Islands (+677)</option>
  <option value="SO">Somalia (+252)</option>
  <option value="ZA">South Africa (+27)</option>
  <option value="KR">South Korea (+82)</option>
  <option value="SS">South Sudan (+211)</option>
  <option value="ES">Spain (+34)</option>
  <option value="LK">Sri Lanka (+94)</option>
  <option value="LC">St. Lucia (+1)</option>
  <option value="SD">Sudan (+249)</option>
  <option value="SR">Suriname (+597)</option>
  <option value="SZ">Swaziland (+268)</option>
  <option value="SE">Sweden (+46)</option>
  <option value="CH">Switzerland (+41)</option>
  <option value="SY">Syria (+963)</option>
  <option value="TW">Taiwan (+886)</option>
  <option value="TJ">Tajikistan (+992)</option>
  <option value="TZ">Tanzania (+255)</option>
  <option value="TH">Thailand (+66)</option>
  <option value="BS">The Bahamas (+1)</option>
  <option value="GM">The Gambia (+220)</option>
  <option value="TL">Timor-Leste (+670)</option>
  <option value="TG">Togo (+228)</option>
  <option value="TK">Tokelau (+690)</option>
  <option value="TO">Tonga (+676)</option>
  <option value="TT">Trinidad and Tobago (+1)</option>
  <option value="TN">Tunisia (+216)</option>
  <option value="TR">Turkey (+90)</option>
  <option value="TM">Turkmenistan (+993)</option>
  <option value="TC">Turks and Caicos Islands (+1)</option>
  <option value="TV">Tuvalu (+688)</option>
  <option value="UG">Uganda (+256)</option>
  <option value="UA">Ukraine (+380)</option>
  <option value="AE">United Arab Emirates (+971)</option>
  <option value="GB">United Kingdom (+44)</option>
  <option value="US" selected>United States of America (+1)</option>
  <option value="UY">Uruguay (+598)</option>
  <option value="VI">US Virgin Islands (+1)</option>
  <option value="UZ">Uzbekistan (+998)</option>
  <option value="VU">Vanuatu (+678)</option>
  <option value="VA">Vatican City (+39)</option>
  <option value="VE">Venezuela (+58)</option>
  <option value="VN">Vietnam (+84)</option>
  <option value="WF">Wallis and Futuna (+681)</option>
  <option value="YE">Yemen (+967)</option>
  <option value="ZM">Zambia (+260)</option>
  <option value="ZW">Zimbabwe (+263)</option>

Example :

Jun 29, 2014

Check if a string is valid JSON in php

A little function to check if a string is valid JSON (JavaScript Object Notation) or not. It takes json string as a parameter and returns true if it is valid otherwise returns false.

If you want to Create a JSON string from mysql database you may visit here.

 function isValidJson($string){
  json_decode($string, true);
  if (json_last_error() == JSON_ERROR_NONE) {
   return true;
  return false;

May 27, 2014

Problems and solutions during installing Magento

Different types of issues are found during installing Magento. Here are some compilation of Magento installation problems and their solutions.

Problem 1 : Database server does not support the InnoDB storage engine while installing magento

Solution 1 :

Go To Line 59 of the file app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php
Change this function

    public function supportEngine()
        $variables  = $this->_getConnection()
            ->fetchPairs('SHOW VARIABLES');
        return (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') ? false : true;

With this

    public function supportEngine()
        $variables  = $this->_getConnection()
            ->fetchPairs('SHOW ENGINES');
        return (isset($variables['InnoDB']) && $variables['InnoDB'] != 'NO');

Problem 2: 404 Not Found Error After Installation

Sometimes after installing magento, clicking on any link results in 404 not found error. This happens because the rewrite module of the server is not enabled. Just enable the mod_rewrite and it will work.

Solution 2:

Enable rewrite_module (mod_rewrite) of your Apache Server

Jan 15, 2014

List all files of a directory in php

Listing all files of a directory in php is quite easy with php DirectoryIterator class. This class provides a simple interface for viewing the contents of filesystem directories.

Here is a simple php function to list all files of a directory. This is a recursive function so that it will list files of all of its subdirectories too.

   function list_directory_contents($dir){
     $dh = new DirectoryIterator($dir);    
     foreach ($dh as $item) {
         if (!$item->isDot()) {
            if ($item->isDir()) {
            } else {
                echo $dir . "/" . $item->getFilename();
                echo "<br>";

  # Call function 
The output will be something like


Jan 14, 2014

Using MySql replace function

MySql has a very useful function replace() which allows you to replace substring or characters. It is really useful while working with huge database table where you want to update certain values with another value. Its syntax is quite simple.

   REPLACE ( field_name, 'find_string', 'replacement_string' );

To update some values in database table use query as follows using replace function.

   UPDATE tutorials SET topic = REPLACE (topic, 'Php', 'Php MySql');

You can also run a select query using this function if you don't want to update table but want to fetch data as replaced. This will only output replaced values and there will be no changes in database.

   SELECT REPLACE (topic, 'Php', 'Php MySql') as new_topic 
   FROM tutorials 
   WHERE topic = 'Php';

Dec 14, 2013

Commonly used abbreviations in php

While working with php or when we talk about php, some abbreviations are more frequently used. I have compiled some most commonly used abbreviations. Here is the list.


    AJAX  =>  Asynchronous JavaScript And XML
    API   =>  Application Programming Interface
    ASCII =>  American Standard Code for Information Interchange
    CMS   =>  Content Management System
    CSS   =>  Cascading Style Sheet
    CGI   =>  Common Gateway Interface
    CLI   =>  Command Line Interface
    DB    =>  DataBase
    DNS   =>  Domain Name System
    DOM   =>  Document Object Model
    FTP   =>  File Transfer Protocol
    GD    =>  Graphics Draw | Gif Draw
    HTML  =>  Hypertext Markup Language
    HTTP  =>  Hypertext Transfer Protocol
    HTTPS =>  Hypertext Transfer Protocol Secure
    IP    =>  Internet Protocol
    IIS   =>  Internet Information Services
    JS    =>  JavaScript  
    JSON  =>  JavaScript Object Notation
    LAMP  =>  Linux Apache MySQL PHP
    MAMP  =>  Macintosh Apache MySQL PHP
    MIME  =>  Multipurpose Internet Mail Extensions
    OOP   =>  Object Oriented Programming
    PCRE  =>  Perl Compatible Regular Expressions
    PEAR  =>  PHP Extension and Application Repository
    PECL  =>  PHP Extension Community Library
    PHP   =>  Hypertext Preprocessor
    PDO   =>  PHP Data Objects
    POSIX =>  Portable Operating System Interface
    RegEx =>  Regular Expression
    REST  =>  Representational State Transfer
    RSS   =>  Really Simple Syndication
    SAPI  =>  Server Application Programming Interface
    SOAP  =>  Simple Object Access Protocol
    SPL   =>  Standard PHP Library
    SMTP  =>  Simple Mail Transfer Protocol
    SQL   =>  Structured Query Language
    INI   =>  INItialization
    SEO   =>  Search Engine Optimization
    PING  =>  Packet InterNet Groper
    SSH   =>  Secure SHell
    SSL   =>  Secure Sockets Layer
    UCS   =>  Universal Character Set
    URI   =>  Uniform Resource Identifier
    URL   =>  Uniform Resource Locator
    UTF   =>  Unicode Transformation Format
    WAMP  =>  Windows Apache MySQL PHP
    WWW   =>  World Wide Web
    XAMPP =>  X (any of four different operating systems) Apache MySQL PHP & Perl
    XML   =>  eXtensible Markup Language
    XML-RPC=> XML Remote Procedure Call
    XSS   =>  cross Site Scripting

Dec 6, 2013

Move list box items from one box to another with jquery

While working with select boxes somewhere you need to use multiple selections and selecting multiple items from a bigger list is not user friendly. Here the idea is to make two select boxes and move items from one box to another. So it becomes more user friendly and looks good when it comes to UX.

It is quite easy to implement this with jquery. Just remove the item from one box and append to another.
You can move all items at once or you can move only selected items.

jQuery to move selected list box items from one box to another

  $('#from option:selected').remove().appendTo('#to'); 

jQuery to move all list box items from one box to another

  $('#from option').remove().appendTo('#to');

The above two lines of jquery does all the trick. Here is the full script. The jquery, css and the html.

    <!doctype html>
    <meta charset="utf-8">
    <title>Move from one select box to another</title>
    <style type="text/css">
    select {
        width: 200px;
        float: left;
    .controls {
        width: 40px;
        float: left;
        margin: 10px;
    .controls a {
        background-color: #222222;
        border-radius: 4px;
        border: 2px solid #000;
        color: #ffffff;
        padding: 2px;
        font-size: 14px;
        text-decoration: none;
        display: inline-block;
        text-align: center;
        margin: 5px;
        width: 20px;
    <script src="">
    function moveAll(from, to) {
        $('#'+from+' option').remove().appendTo('#'+to); 
    function moveSelected(from, to) {
        $('#'+from+' option:selected').remove().appendTo('#'+to); 
    function selectAll() {
        $("select option").attr("selected","selected");

    <form name="selection" method="post" onSubmit="return selectAll()"> 
    <select multiple size="10" id="from">
      <option value="html">Html</option>
      <option value="css">Css</option>
      <option value="google">Google</option>
      <option value="javascript">Javascript</option>
      <option value="jquery">Jquery</option>
      <option value="regex">Regex</option>
      <option value="php">Php</option>
      <option value="mysql">Mysql</option>
      <option value="xml">Xml</option>
      <option value="json">Json</option>
    <div class="controls"> 
        <a href="javascript:moveAll('from', 'to')">&gt;&gt;</a> 
        <a href="javascript:moveSelected('from', 'to')">&gt;</a> 
        <a href="javascript:moveSelected('to', 'from')">&lt;</a> 
        <a href="javascript:moveAll('to', 'from')" href="#">&lt;&lt;</a> </div>
    <select multiple id="to" size="10" name="topics[]"></select>

See the demo of the code.

>> > < <<

Nov 27, 2013

Convert currency using google finance calculator in php

Earlier we used to Convert currency using Google api. But as Google has closed its iGoogle service from 1st Nov 2013, this api will no longer work. But we have an alternative to convert currency using google finance calculator.

Here is a little code snippet that can be used to convert currency from one format to another.
It takes three parameters The amount to be converted, convert from and convert to

  function convertCurrency($amount, $from, $to){
    $url  = "$amount&from=$from&to=$to";
    $data = file_get_contents($url);
    preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
    $converted = preg_replace("/[^0-9.]/", "", $converted[1]);
    return round($converted, 3);

  # Call function  
  echo convertCurrency(1, "USD", "INR");

The above php function returns something like 62.285

The Currency formats can be of following types

    AED => United Arab Emirates Dirham (AED)
    AFN => Afghan Afghani (AFN)
    ALL => Albanian Lek (ALL)
    AMD => Armenian Dram (AMD)
    ANG => Netherlands Antillean Guilder (ANG)
    AOA => Angolan Kwanza (AOA)
    ARS => Argentine Peso (ARS)
    AUD => Australian Dollar (A$)
    AWG => Aruban Florin (AWG)
    AZN => Azerbaijani Manat (AZN)
    BAM => Bosnia-Herzegovina Convertible Mark (BAM)
    BBD => Barbadian Dollar (BBD)
    BDT => Bangladeshi Taka (BDT)
    BGN => Bulgarian Lev (BGN)
    BHD => Bahraini Dinar (BHD)
    BIF => Burundian Franc (BIF)
    BMD => Bermudan Dollar (BMD)
    BND => Brunei Dollar (BND)
    BOB => Bolivian Boliviano (BOB)
    BRL => Brazilian Real (R$)
    BSD => Bahamian Dollar (BSD)
    BTN => Bhutanese Ngultrum (BTN)
    BWP => Botswanan Pula (BWP)
    BYR => Belarusian Ruble (BYR)
    BZD => Belize Dollar (BZD)
    CAD => Canadian Dollar (CA$)
    CDF => Congolese Franc (CDF)
    CHF => Swiss Franc (CHF)
    CLF => Chilean Unit of Account (UF) (CLF)
    CLP => Chilean Peso (CLP)
    CNH => CNH (CNH)
    CNY => Chinese Yuan (CN¥)
    COP => Colombian Peso (COP)
    CRC => Costa Rican Colón (CRC)
    CUP => Cuban Peso (CUP)
    CVE => Cape Verdean Escudo (CVE)
    CZK => Czech Republic Koruna (CZK)
    DEM => German Mark (DEM)
    DJF => Djiboutian Franc (DJF)
    DKK => Danish Krone (DKK)
    DOP => Dominican Peso (DOP)
    DZD => Algerian Dinar (DZD)
    EGP => Egyptian Pound (EGP)
    ERN => Eritrean Nakfa (ERN)
    ETB => Ethiopian Birr (ETB)
    EUR => Euro (€)
    FIM => Finnish Markka (FIM)
    FJD => Fijian Dollar (FJD)
    FKP => Falkland Islands Pound (FKP)
    FRF => French Franc (FRF)
    GBP => British Pound Sterling (£)
    GEL => Georgian Lari (GEL)
    GHS => Ghanaian Cedi (GHS)
    GIP => Gibraltar Pound (GIP)
    GMD => Gambian Dalasi (GMD)
    GNF => Guinean Franc (GNF)
    GTQ => Guatemalan Quetzal (GTQ)
    GYD => Guyanaese Dollar (GYD)
    HKD => Hong Kong Dollar (HK$)
    HNL => Honduran Lempira (HNL)
    HRK => Croatian Kuna (HRK)
    HTG => Haitian Gourde (HTG)
    HUF => Hungarian Forint (HUF)
    IDR => Indonesian Rupiah (IDR)
    IEP => Irish Pound (IEP)
    ILS => Israeli New Sheqel (₪)
    INR => Indian Rupee (Rs.)
    IQD => Iraqi Dinar (IQD)
    IRR => Iranian Rial (IRR)
    ISK => Icelandic Króna (ISK)
    ITL => Italian Lira (ITL)
    JMD => Jamaican Dollar (JMD)
    JOD => Jordanian Dinar (JOD)
    JPY => Japanese Yen (¥)
    KES => Kenyan Shilling (KES)
    KGS => Kyrgystani Som (KGS)
    KHR => Cambodian Riel (KHR)
    KMF => Comorian Franc (KMF)
    KPW => North Korean Won (KPW)
    KRW => South Korean Won (₩)
    KWD => Kuwaiti Dinar (KWD)
    KYD => Cayman Islands Dollar (KYD)
    KZT => Kazakhstani Tenge (KZT)
    LAK => Laotian Kip (LAK)
    LBP => Lebanese Pound (LBP)
    LKR => Sri Lankan Rupee (LKR)
    LRD => Liberian Dollar (LRD)
    LSL => Lesotho Loti (LSL)
    LTL => Lithuanian Litas (LTL)
    LVL => Latvian Lats (LVL)
    LYD => Libyan Dinar (LYD)
    MAD => Moroccan Dirham (MAD)
    MDL => Moldovan Leu (MDL)
    MGA => Malagasy Ariary (MGA)
    MKD => Macedonian Denar (MKD)
    MMK => Myanma Kyat (MMK)
    MNT => Mongolian Tugrik (MNT)
    MOP => Macanese Pataca (MOP)
    MRO => Mauritanian Ouguiya (MRO)
    MUR => Mauritian Rupee (MUR)
    MVR => Maldivian Rufiyaa (MVR)
    MWK => Malawian Kwacha (MWK)
    MXN => Mexican Peso (MX$)
    MYR => Malaysian Ringgit (MYR)
    MZN => Mozambican Metical (MZN)
    NAD => Namibian Dollar (NAD)
    NGN => Nigerian Naira (NGN)
    NIO => Nicaraguan Córdoba (NIO)
    NOK => Norwegian Krone (NOK)
    NPR => Nepalese Rupee (NPR)
    NZD => New Zealand Dollar (NZ$)
    OMR => Omani Rial (OMR)
    PAB => Panamanian Balboa (PAB)
    PEN => Peruvian Nuevo Sol (PEN)
    PGK => Papua New Guinean Kina (PGK)
    PHP => Philippine Peso (Php)
    PKG => PKG (PKG)
    PKR => Pakistani Rupee (PKR)
    PLN => Polish Zloty (PLN)
    PYG => Paraguayan Guarani (PYG)
    QAR => Qatari Rial (QAR)
    RON => Romanian Leu (RON)
    RSD => Serbian Dinar (RSD)
    RUB => Russian Ruble (RUB)
    RWF => Rwandan Franc (RWF)
    SAR => Saudi Riyal (SAR)
    SBD => Solomon Islands Dollar (SBD)
    SCR => Seychellois Rupee (SCR)
    SDG => Sudanese Pound (SDG)
    SEK => Swedish Krona (SEK)
    SGD => Singapore Dollar (SGD)
    SHP => Saint Helena Pound (SHP)
    SLL => Sierra Leonean Leone (SLL)
    SOS => Somali Shilling (SOS)
    SRD => Surinamese Dollar (SRD)
    STD => São Tomé and Príncipe Dobra (STD)
    SVC => Salvadoran Colón (SVC)
    SYP => Syrian Pound (SYP)
    SZL => Swazi Lilangeni (SZL)
    THB => Thai Baht (฿)
    TJS => Tajikistani Somoni (TJS)
    TMT => Turkmenistani Manat (TMT)
    TND => Tunisian Dinar (TND)
    TOP => Tongan Paʻanga (TOP)
    TRY => Turkish Lira (TRY)
    TTD => Trinidad and Tobago Dollar (TTD)
    TWD => New Taiwan Dollar (NT$)
    TZS => Tanzanian Shilling (TZS)
    UAH => Ukrainian Hryvnia (UAH)
    UGX => Ugandan Shilling (UGX)
    USD => US Dollar ($)
    UYU => Uruguayan Peso (UYU)
    UZS => Uzbekistan Som (UZS)
    VEF => Venezuelan Bolívar (VEF)
    VND => Vietnamese Dong (₫)
    VUV => Vanuatu Vatu (VUV)
    WST => Samoan Tala (WST)
    XAF => CFA Franc BEAC (FCFA)
    XCD => East Caribbean Dollar (EC$)
    XDR => Special Drawing Rights (XDR)
    XOF => CFA Franc BCEAO (CFA)
    XPF => CFP Franc (CFPF)
    YER => Yemeni Rial (YER)
    ZAR => South African Rand (ZAR)
    ZMK => Zambian Kwacha (1968-2012) (ZMK)
    ZMW => Zambian Kwacha (ZMW)
    ZWL => Zimbabwean Dollar (2009) (ZWL)

Nov 16, 2013

Get mimetype of an image in php

Mime type is an standard identifier of a file which indicates the type of data a file contains. It has two parts divided with a slash(/) like image/png.

The built in function of php getimagesize() gives lots of information about an image. And this function is enough to get the mime type of an image. It also returns Width and Height of the image.

GD Library is also not required to use this function.
   $image = getimagesize("imagename.jpg");
   echo $image['mime'];

It returns an array with upto 7 elements.
    [0] => 200
    [1] => 125
    [2] => 2
    [3] => width="200" height="125"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
Index 0 and 1 of the array contains the width and height of the array respectively.

This function can play a big role if you are creating an image upload script and want to limit the size of the image. Suppose if you don't want to upload an image greater than 400x250.

Just check width and height of the image using getimagesize() function and return respective messages to user to upload image smaller than the required size.


Copyright @ 2013 Altaf hussain's blog.