Thursday, 19 May 2016

JavaScript encodeURIComponent function - Encode and Decode

javaScript encodeURIComponent function - Encode and Decode

Question: What is encodeURI?
It encodes only symbols that is not allowed in a URL.


Question: What is encodeURIComponent?
It encodes Whole URL. Its mainly use when you want to send the URL in a parameter.


Question: What is use of escape?
It is deprecated and recommended not to use.


Question: How to use URL encode in Javascript using encodeURIComponent?
var encodedURL = encodeURIComponent('http://www.onlinevideoswatch.com/tools/javascript-urlencode-online');
console.log(encodedURL);//http%3A%2F%2Fwww.onlinevideoswatch.com%2Ftools%2Fjavascript-urlencode-online



Question: From where we can URL encode in Javascript online?
http://www.onlinevideoswatch.com/tools/javascript-urlencode-online


Question: How to use URL decodeed in Javascript using decodeURIComponent?
var decodedURL = decodeURIComponent('http%3A%2F%2Fwww.onlinevideoswatch.com%2Ftools%2Fjavascript-urlencode-online');
console.log(encodedURL);//http://www.onlinevideoswatch.com/tools/javascript-urlencode-online



Question: From where we can URL decode in Javascript online?
http://www.onlinevideoswatch.com/tools/javascript-urldecode-online


Question: What is the difference between a URI, a URL and a URN?
Just See Examples
Suppose we have this link: http://www.onlinevideoswatch.com/tools/javascript-urldecode-online#name=encodeing
URI - Uniform Resource Identifer
http://www.onlinevideoswatch.com/tools/javascript-urldecode-online#name=encodeing%20Data

URL-Uniform Resource Locator
http://www.onlinevideoswatch.com/tools/javascript-urldecode-online

URN - Uniform Resource Name
onlinevideoswatch.com/tools/javascript-urldecode-online#name=encodeing%20Data





Wednesday, 18 May 2016

How to add element to array in php?

how to add element to array in php?

Question: How to add element to array?
$arrayData = array(0=>'one',1=>'two',3=>'three'); 
print_r($arrayData);
/*
 Array ( [0] => one [1] => two [3] => three ) 
 */
$arrayData['4']='four';


print_r($arrayData);
/**
Array ( [0] => one [1] => two [3] => three [4] => four ) 
 * 
 */



Question: How to add multiple element in array?
$arrayData = array(0=>'one',1=>'two',3=>'three'); 
print_r($arrayData);
/*
 Array ( [0] => one [1] => two [3] => three ) 
 */
$arrayData['4']='four';
$arrayData['5']='five';


print_r($arrayData);
/**
Array ( [0] => one [1] => two [3] => three [4] => four [5] => five ) 
 * 
 */



Question: How to replace multiple array element with single array?
$arrayData = array(0=>'one',1=>'two',3=>'three',4=>'four',5=>'five',6=>'six'); 
print_r($arrayData); echo "
";
/*
 * Array ( [0] => one [1] => two [3] => three [4] => four [5] => five [6] => six ) 
 */
array_splice($arrayData, 1,2,array('r'=>'replaced'));


print_r($arrayData);
/**
Array ( [0] => one [1] => replaced [2] => four [3] => five [4] => six ) 
 * 
 */



Question: How to add element to an begining of array?
$arrayData = array(0=>'one',1=>'two',3=>'three'); 
print_r($arrayData);
/*
Array ( [0] => one [1] => two [3] => three )  
 */
array_unshift($arrayData, "four", "five");


print_r($arrayData);
/**
Array ( [0] => four [1] => five [2] => one [3] => two [4] => three ) 
 * 
 */



Question: How to add elements at the end of array?
$arrayData = array(0=>'one',1=>'two',3=>'three'); 
print_r($arrayData);
/*
Array ( [0] => one [1] => two [3] => three )  
 */
array_push($arrayData, "four", "five");


print_r($arrayData);
/**
Array ( [0] => four [1] => five [2] => one [3] => two [4] => three ) 
 * 
 */