Thursday, 7 November 2013

Dependent datepicker Jquery

Dependent datepicker Jquery

HTML:
    <div class="input_box">
        <input type="text" readonly="readonly" id="start_date" name="date"/>
    </div>
    <div class="input_box">
        <input type="text" readonly="readonly" id="end_date" name="date"/>
    </div>

JAVA SCRIPT CODE:

    $("#start_date").datepicker({
        minDate: 0,
        onSelect: function(selected) {
            var selected_date1 = $("#start_date").val();
            $("#end_date").datepicker("option","minDate", selected_date1)
        }
    });
 

    $("#end_date").datepicker({minDate: +1});

Live Demo :http://jsfiddle.net/g6kUR/1/

Wednesday, 16 October 2013

Browser close & Redirection event in Javascript.

Browser close & Redirection  event in Javascript.

window.onbeforeunload = function(e) {
    // check condition
        alert('Close');
     

    };

Monday, 7 October 2013

Checking if URL contains "HTTP" OR "HTTPS"

Checking if URL contains "HTTP" OR "HTTPS"

Code
<?php
    $site = "https://www.abc.com?id=123&r=sdsdsdsdd";
    $url = parse_url($site);
    if(in_array("http", $url) || in_array("https", $url)) {
        echo "Present";
    }
    else{
    echo "Not Present";
    }
?>

Note:  parse_url : Parse URL ans returns its components.

OUTPUT: 

Present

Friday, 4 October 2013

Table row and CSS

HTML:
A B C
Cell #1 Cell #2 Cell #3
Cell #4 Cell #5 Cell #6
Cell #7 Cell #8 Cell #9

<table border="2" class="text_12">
<tr>
    <td>A</td>
    <td>B</td>
    <td>C</td>
</tr>
<tr>
    <td>Cell #1</td>
    <td>Cell #2</td>
    <td>Cell #3</td>
</tr>
<tr>
    <td>Cell #4</td>
    <td>Cell #5</td>
    <td>Cell #6</td>
</tr>
<tr>
    <td>Cell #7</td>
    <td>Cell #8</td>
    <td>Cell #9</td>
</tr>
</table>


CSS:
<style>
table.text_12 tr td:nth-child(2){
    background-color:red;
}
table.text_12 tr+tr td:nth-child(1){
    background-color:green;
}
</style>

Thursday, 5 September 2013

Display twitter feed on website using PHP

Display twitter feed on website using php
First -> include "TwitterAPIExchange.php" and "twitteroauth.php" files.
<?php
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
require_once("twitteroauth.php"); //Path to twitteroauth library
define('ACCESS_TOKEN','your access token');
define('ACCESS_SECRET','your access secret');
define('CONSUMER_KEY','your consumer key');
define('CONSUMER_SECRET','your consumer secret key');

$twitteruser = "ABC"; // tweeter use
$notweets = 1; // Number of tweets you want to show
$consumerkey = "12345";
$consumersecret = "123456789";
$accesstoken = "123456789";
$accesstokensecret = "12345";

function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}

$connection = getConnectionWithAccessToken(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET);

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?trim_user=t&screen_name=".$twitteruser."&count=".$notweets);
$status = '';
foreach($tweets as $key){
$status = $key->text;
}
echo $status;
?>

Tuesday, 27 August 2013

PHP extract link from <a> tag

<?php

$string = "<a href=\"www.xyz.com/index.php\">My URL</a>\n";
preg_match('|<a.+?href\="(.+?)".*?>(.+?)</a>|i', $string, $match);
$url = $match[1];
$text = $match[2];
echo "Link: ".$url;
echo "Url: ".$text;
?>

Output:
Link: www.xyz.com/index.php
Url: My URL

Friday, 9 August 2013

Javascript Email validation including domains with dashes

Java Script Email validation including domains with dashes using Regular Expressions

$match = (/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/);




Friday, 21 June 2013

Diffrence between Plugin and Widgets in Wordpress

 Wordpress Plugin :
Wordpress plugin are the function that do something to your website in which we can add our logic and concept. Plugin are for the back-end and never be visible to you or the public.

Wordpress Widgets:

Wordpress Widgets is an object you can add to your sidebar usually derived from a plugin. Widgets are always plugins, but plugins don't always have widgets. Or we can say a widget is a plugin that you can drag and drop in your sidebar.


Tuesday, 11 June 2013

Missing element in Array Using PHP

Missing element in Array Using PHP

By using arry_diff function we can easily find the missing element in a given array.
Example:
<?php

$array = array(1,2,3,4,7,9,10); //given array
$array_range = range(1,max($array)); // find the range of array using range() function
echo "Array range :";
print_r($array_range);
echo "<br/>";
$missing_element = array_diff($array_range,$array) ;
echo "Array missing elements :";
print_r($missing_element); // get the missing elements


?>

Output:
Array range :Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 )
Array missing elements :Array ( [4] => 5 [5] => 6 [7] => 8 )

Monday, 10 June 2013

Compress and Uncompress string in PHP

In php, it is possible to compress and uncompress a string.
<?php
$string ="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut elit id mi ultricies adipiscing. Nulla facilisi. Praesent pulvinar, sapien vel feugiat vestibulum, nulla dui pretium orci,
non ultricies elit lacus quis ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
//we use gzcompress function to compress the string.
$compress = gzcompress($string);
echo "<b>Actual String length :</b>".strlen($string)."<br/>";

echo "<b>Actual String Data :</b>";
print_r($string);
echo "<br/>";
echo "<br/>";

echo "<b>String length after compress :</b>".strlen($compress)."<br/>";
echo "<b>String data after compress :</b>";
print_r($compress);
echo "<br/>";
echo "<br/>";
// Decompress through gzuncompress
$orignal = gzuncompress($compress)."<br/>";
echo "<b>String length after de-compress :</b>".strlen($orignal);
echo "<br/>";
echo "<b>String Data after de-compress :</b>";
print_r($orignal);
?>

Output :

Actual String length :282
Actual String Data :Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut elit id mi ultricies adipiscing. Nulla facilisi. Praesent pulvinar, sapien vel feugiat vestibulum, nulla dui pretium orci, non ultricies elit lacus quis ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

String length after compress :159
String data after compress :xœQj A Cÿ ½ƒ °ìIBé ÜY' <žéØÎù»Ý¯|çO !=ÝÆÒ Î¨ŽcØX &¤knhÃC[jÖ‚ œŒF@¹ã«¼¡òràN”åb£ÆKú?h&¸K£1¸ã{‰†zb–=é²6„Lªã©†»Öƒ’§ŽäOYõ ~5 E̥ɓt¬Æ Ÿ >üeõB1i ø-ž žºãöæÃ?1*g^

String length after de-compress :287
String Data after de-compress :Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut elit id mi ultricies adipiscing. Nulla facilisi. Praesent pulvinar, sapien vel feugiat vestibulum, nulla dui pretium orci, non ultricies elit lacus quis ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Thursday, 6 June 2013

Arbitrary Number of Function Arguments in PHP


In PHP there is a method to pass arbitrary number of function arguments.

For Example:

<?php
function my_function() {

    $arguments = func_get_args();// returns an array of all passed arguments

    foreach ($arguments as $key => $value) {
        echo "State Name".($key+1).": $value<br/>";
    }

}
echo "Without argument<br/>";
$a = my_function();
print_r($a);
echo "<hr><br/>";

echo "Single argument<br/>";
$b = my_function('Delhi');
print_r($b);
echo "<hr><br/>";

echo "Multiple argument call<br/>";
$c = my_function('Delhi','Mumbai','Uttrakhand');
print_r($c);
?>

Output:
Without argument


Single argument
State Name1: Delhi


Multiple argument call
State Name1: Delhi
State Name2: Mumbai
State Name3: Uttrakhand

Thursday, 30 May 2013

PHP ARRAY

Like another programming language php also having array.An array is define as a series of elements of the same type placed in contiguous memory locations.

Type of array in PHP

  1. Numeric Array.
  2. Associative Array.
  3. Multidimensional Array.
Numeric Array: - 

  • In numeric array store each element with a numeric index.There are generally two methods to create a numeric array:
  1. $computer = array("Acer”,”Lenovo”,”deal”,”hp”);                                                                           In this the index value are automatically assigned to each array element starts from 0.
  2.                                                                                                                                              $computer[0] = “Acer”;                                                                                                 $computer[1] = “Lenovo”;                                                                                               $computer[2] = “deal”;                                                                                                  $computer[3] = “hp”;                                                                                                                      In this we assign the index value to each element in array.
Example:
                        <?php
                        $computer[0] = “Acer”;
                        $computer[1] = “Lenovo”;
                        $computer[2] = “ deal”;
                        $computer[3] = “hp”;
                        Echo $computer[0].”and”.$computer[1].”are cheap and best”;
                        ?>
Output: Acer and Lenovo are cheap and best
Associative Array:  In this each id is associative with a value.
Numeric array is not best in storing data about specific named so we can use associative array. With associative array we can use the value as key and assign to them.
Example :     <?php 
                      $employee = array (“Ram”=>23,”Sham”=>24,”Pankaj”=>23);  Or
                      $employee [‘Ram’] =”23”;
                      $employee [‘Sham’] = “24”;
                      $employee [‘Pankaj’] = “23”;
                      echo “Ram is”.$employee[‘Ram’].”Year old”; ?>
Output: Ram is 23 year old.
Multidimensional Array: In this an array element contain array or we can say that each element in the main array can also be an array. And each element in the sub-array can be an array.
Example:
Array
                        (
                        [kumar]=> array
                                    (
                                                [0] =>pankaj
                                                [1]=>amit
                                    )
                        [singh]=> array
                                    (
                                                [0]=> sumit
                                    )
                        ) 

Tuesday, 28 May 2013

Change the page title case in Wordpress

One can change the page title case according to page post id.
  <?php
     
       $page_title_case_change_arr = array(1,2,55);
       $page_id = $post->ID;
       $head_style = "";
       if(in_array($page_id,$page_title_case_change_arr)){
            $head_style = "style='text-transform:uppercase'";
       }
      echo "<h2".$head_style.">".$page_title."</h2>"; ?>
  ?>

In the above example first you have to declare the array of page where you want to change the case of header title in $page_title_case_change_arr variable. Then get page post ID by $page_id.

Then create a empty variable named as $head_style. After that check if a $page_id  value exists in an array if it's then add a inline css.

Monday, 27 May 2013

Array Key Case Change


Using array_change_key_case function we can easily change case of array key.
Syntax: array array_change_key_case (array, $input);

Example: 
        $array_exp = array("my"=>1, "country"=>2);
        $output = array_change_key_case($array_exp,CASE_UPPER);
        print_r($output);

       Output: Array ( [MY] => 1 [COUNTRY] => 2 )

case either CASE_LOWER  or UPPER_CASE

Thursday, 23 May 2013

Add Script in Wordpress


Add Script in Wordpress:  
         Syntax: wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer);
          
           $handler: Name use to handle the script.
           $scr :Is the URL of the script.
           $ver: define script version number.
          
Example:
         <?php

          function add_script(){
           wp_enqueue_script('Jquery', plugin_url('jquery-ui-1.10.1.custom.min'), '');
           }
          add_action('int',add_script);

         ?>
      
          
    

Monday, 20 May 2013

Add menu page with diffrent name from sub menu page in Wordpress

In wordpress if you are creating  a plugin the first sub menu page name is same as of plugin main menu page.
like if the name of plugin menu is Fund the by default the name of its first sub menu is also Fund.

To change this sub menu page you can make the slug for the submenu page equal that of the top level page.

add_action('admin_menu', 'my_plugin_menu');

function my_plugin_menu() {  
    add_menu_page('Page Title', 'Menu Title', 'manage_options', 'mymenu', 'display_menu);
    add_submenu_page('mymenu', 'sub_menu1 ', 'Sub menu name', 'manage_options','mymenu');
   add_submenu_page('mymenu', 'sub_menu2 ', 'Sub menu name2', 'manage_options','mymenu2');


   

Error Reporting in PHP


In this article we are discussing error reporting in php and we also discuss why  error reporting is important during development and why it is important to turn it off.

for example:
<?php
echo $var = "pan "
$var2 = "pan2";

?>

In this example i missing the line terminator or $var which is a semi colon. At that moment my error reporting is off. So if i run this code nothing has to be return  no error and no output. This is because of error reporting off.

So we have to go to the php.ini file located in php folder and  find error_reporting and modified its value by 0 to E_ALL and then save the file and restart Apache server. And then if we refresh our output page the it will show an parse error.

Wednesday, 15 May 2013

Class change using Javascript.


<Html>
<head>
<style>
.intro
{
color:green;
background-color:blue;

}
</style>
</head>
<body>

 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
alert("hello")
});

function fun1()
{

$('p').addClass('intro');

}

function fun2()
{

$('p').removeClass('intro');

}

function fun3()
{

$('p').toggleClass('intro');

}
 </script>
<p>Hello</p>
<input type="button" onclick="fun1()" value="pune1">
<input type="button" onclick="fun2()" value="pune2">
<input type="button" onclick="fun3()" value="pune3">
</body>
</html>

Tuesday, 14 May 2013

Hide On Click


<html>
<head>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div id="d1">
Test Content
</div>
<span id="s1">click me to hide-></span>
<script>
$("#s1").click(function(){
$("#d1").hide();
})
</script>
</body>
</html>

Saturday, 11 May 2013

PHP ARRAY


Like another programming language php also having array. Array is a special variable which can used to store multiple values of same data type.
Array is used to hold all values under one single name and we used that value by referring that name of array. Array can be accessed by its index value.

Types of Array:

  1. Numeric Array
  2. Associative Array
  3. Multidimensional Array.
  • Numeric Array:  In numeric array store each element with a numeric index. There are generally two methods to create a numeric array:
                  a)      $computer = array("Acer”,”Lenovo”,”deal”,”hp”);
     In this the index value are automatically assigned to each array element starts from 0.
b)      $computer[0] = “Acer”;
c)      $computer[1] = “Lenovo”;
d)     $computer[2] = “deal”;
e)      $computer[3] = “hp”;
                     In this we assign the index value to each element in array.
Example:
<?php
                        $computer[0] =  “Acer”;
                        $computer[1] = “Lenovo”;
                        $computer[2] = “ deal”;
                        $computer[3] = “hp”;
                        Echo $computer[0].”and”.$computer[1].”are cheap and best”;
 ?>

Output: Acer and Lenovo are cheap and best.

  • Associative Array: In this each id is associative with a value.
Numeric array is not best in storing data about specific named so we can use associative array. With associative array we can use the value as key and assign to them.

Example :
$employee = array (“Ram”=>23,”Sham”=>24,”Pankaj”=>23);
                                                      Or
                  $employee [‘Ram’] =”23”;
                  $employee [‘Sham’] = “24”;
                  $employee [‘Pankaj’] = “23”;
Example :
<?php
                  $employee [‘Ram’] =”23”;
                  $employee [‘Sham’] = “24”;
                  $employee [‘Pankaj’] = “23”;
                  echo “Ram is”.$employee[‘Ram’].”Year old”;
 ?>
Output: Ram is 23 year old.

  • Multidimensional Array.: In this an array element contain array or we can say that each element in the main array can also be an array. And each element in the sub-array can be an array.
Example:
Array
                        (
                        [kumar]=> array
                                    (
                                                [0] =>pankaj
                                                [1]=>amit
                                    )
                        [singh]=> array
                                    (
                                                [0]=> sumit
                                    )
                        )




Friday, 10 May 2013

Variables in PHP

Variables are used to store information or a value to its. Like other programming language php have its own variable .but in php there is no need to define its data type it will be automatically regret its vale that it is of integer or character type.

In php variable define with a sigh of ‘$’ i.e.
$a, $abc etc.
The first character after $ must be character or underscore. The remaining character in name may be letter , number or underscore.
Syntax :
$variable_name = value;
Example:
$a
$a=10;
$b=20;
$c= $a+$b;

Open a Connection to the MySQL Server in PHP

 Basic syntex:

mysql_connect("hostname","usename","password","dbname")

Example:
<?php
     $con= mysql_connect("xyz.com","pan","pan123","my_db");
     if(!con){
          echo "Could not connect to database".mysql_connect_error();
         
      }
?>