Friday 27 April 2012

PHP Interview question 10


31) How can we get second of the current time using date function?
Ans :      $second = date("s");      
 
32) How can we convert the time zones using PHP?
Ans :      By using date_default_timezone_get and date_default_timezone_set function on PHP 5.1.0
<?php
// Discover what 8am in Tokyo relates to on the East Coast of the US   
// Set the default timezone to Tokyo time:
date_default_timezone_set('Asia/Tokyo');   
// Now generate the timestamp for that particular timezone, on Jan 1st, 2000
$stamp = mktime(8, 0, 0, 1, 1, 2000);   
// Now set the timezone back to US/Eastern
date_default_timezone_set('US/Eastern');   
// Output the date in a standard format (RFC1123), this will print:
// Fri, 31 Dec 1999 18:00:00 EST
echo '<p>', date(DATE_RFC1123, $stamp) ,'</p>';?>

33) What is meant by urlencode and urldocode?
Ans :      URLencode returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.
urldecode decodes any %## encoding in the given string.

34) What is the difference between the functions unlink and unset?
Ans :      unlink() deletes the given file from the file system.
unset() makes a variable undefined.

35) How can we register the variables into a session?
Ans :      $_SESSION['name'] = "sonia";

No comments:

Post a Comment