Jun 7, 2015

Filter list items with jQuery

Sometimes while working with list items or contents, we need to filter out the list items or contents for some matching records. We can implement this using jQuery with ease. Here is a little jQuery code snippet to implement local search.

  <script type="text/javascript" 
  <script type="text/javascript">
  $(document).ready(function(e) {
    var val = $(this).val();
      ($(this).text().search(new RegExp(val, "i")) === -1) 
             ? $(this).hide() : $(this).show();

  <input type="text" id="search" />
  <ul class="list">
    <li>New Zealand</li>
    <li>South Africa</li>
    <li>Sri Lanka</li>
    <li>West Indies</li>


  • Australia
  • Bangladesh
  • India
  • New Zealand
  • Pakistan
  • South Africa
  • Sri Lanka
  • West Indies

Jun 6, 2015

Check uncheck all checkboxes with jQuery

Use jQuery prop function to check or uncheck form check boxes.
Its javascript version is available in another article named Check uncheck all checkboxes with javascript

The Html Form

  <script type="text/javascript" 
  <script type="text/javascript">
  $(document).ready(function(e) {
       $('input:checkbox').prop('checked', this.checked);  
  <form name="checkForm">
  <input type="checkbox" id="checkAll">Check/Uncheck All
  <input type="checkbox" name="one" value ="one">One
  <input type="checkbox" name="two" value ="two">Two
  <input type="checkbox" name="three" value ="three">Three
  <input type="checkbox" name="four" value ="four">Four
  <input type="checkbox" name="five" value ="five">Five

The Example

Check/Uncheck All

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 = json_decode($string);
  return (is_object($json) && json_last_error() == JSON_ERROR_NONE) ? true : false;
 #How to use

    echo "Valid Json";
    echo 'Invalid Json' ; 

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


Copyright @ 2015 Altaf Hussain's Blog.