Showing posts from January, 2016

Convert JSON string to Array in php

$json_string='{ "title": "PHP: The Definitive Guide", "author": "Arun Verma", }';$res=json_decode($json,true);echo$res ['title']; //PHP: The Definitive Guide

Scroll to a div using jquery

$("#button").click(function() {
    $('html, body').animate({
        scrollTop: $("#myDiv").offset().top
    }, 2000);
<div id="button">Go to my div</div>
<div class="div">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable con…

Radio button validation using jQuery validate

<script language="javascript">
          Color:{ required:true }
            required:"Please select a Color<br/>"
        errorPlacement: function(error, element)
            if (":radio") )
                error.appendTo( element.parents('.container') );
            { // This is the default behavior
                error.insertAfter( element );
.error{ color:red; font-family:verdana, Helvetica;}
<form id="myform" >
  <label for='Color'>Select one color:</label>
 <p class='container'>
<label><input type='radio' name='Color' value='Red' />Red</lab…

How to use page numbers in Codeigniter pagination?

$config["total_rows"]     = $this->Hr_model->count_staff_total('tbl_staff');   
        $config["base_url"]     = base_url()."hr/index";
        $config["per_page"]        = 10;
        $config['use_page_numbers'] = TRUE;
        $page_num = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

        $offset = ($page_num  == NULL) ? 0 :
                  ($page_num * $config['per_page']) - $config['per_page'];

        $data["links"]          = $this->pagination->create_links();
        $record_list = $this->Hr_model->getAllStaff($offset,$config['per_page']);

Difference between onload() and $.ready() in jQuery

The main differences between the two are: Body.Onload() event will be called only after the DOM and associated resources like images got loaded, but jQuery's document.ready() event will be called once the DOM is loaded i.e., it wont wait for the resources like images to get loaded. Hence, the functions in jQuery's ready event will get executed once the HTML structure is loaded without waiting for the resources.We can have multiple document.ready() in a page but Body.Onload() event cannot.To know more Click Here

How to get template image path in wordpress?

<img src="<?php echo get_template_directory_uri();?>/images/logo.jpg" />

src="<?php echo base_url()?>theme_dir/image_dir/img.ext" As well
src="<?php bloginfo('template_url'); ?>/image_dir/img.ext"

Get domain name from url using php

function get_domain_name($url)
  $pieces = parse_url($url);
  $domain = isset($pieces['host']) ? $pieces['host'] : '';
  if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
    return $regs['domain'];
  return false;
print get_domain_name("");
// outputs ''