Thursday, 19 May 2016

Convert time in HH:MM:SS format to seconds

Convert time in HH:MM:SS format to seconds

Use below PHP Function to convert time(hh:mm:ss) to seconds.
function getSecondsFromHMS($time) {
    $timeArr = array_reverse(explode(":", $time));    
    $seconds = 0;
    foreach ($timeArr as $key => $value) {
        if ($key > 2)
            break;
        $seconds += pow(60, $key) * $value;
    }
    return $seconds;
}


Give few examples to use getSecondsFromHMS.
echo  getSecondsFromHMS('00:00:35'); //35

echo getSecondsFromHMS('00:35:35'); //2135

echo getSecondsFromHMS('35:35:35'); //128135

echo getSecondsFromHMS('135:35:35'); //488135



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