Question1 : How to use of header() functions in php?
Answer:
1. redirect from current page to another:
2 3 4 |
header("Location: newpage.php"); |
2. To send HTTP status code
2 3 4 |
header("HTTP/1.0 404 Not Found"); |
3. To send Send a raw HTTP header
2 3 4 |
header('Content-Type: application/pdf'); |
Question2: Types of inheritance supported by PHP?
Answer: There are following type of inheritance
Single Inheritance – Support by PHP
Multiple Inheritance – Not support
Hierarchical Inheritance – Support by PHP
Multilevel Inheritance – Support by PHP
Question3: Difference between the functions unlink and unset?
Answer: unlink is used to remove the file from server and unset is used to remove the variable.
Question4: What are default session time and path?
Answer: Default Session Time: 1440 seconds AND Default Session Path: /tmp folder in server.
Question 5: How to add 10 mins to a date?
Answer:
2 3 4 5 6 |
$date = date("Y-m-d H:i:s"); To add 10mins to date we use following function: date("Y/m/d h:i:s", strtotime("+10 minutes", $date)); |
Question6: What is PEAR?
Answer: PEAR ( PHP Extension and Application Repository) is a framework and repository for reusable PHP components. It is used to install the application package.
Question 7: How to get Path From URL in php?
Answer:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
we use the parse_url() to get path of form url. <strong>Example:</strong> $url = "https://www.tutorialswebsite.com/category/php.html"; $path = parse_url($url); print_r($path); /**Array ( [scheme] => http [host] => tutorialswebsite.com [path] => /category/php.html )*/ |
Question8: What is the use of MIME?
Answer: Full form of MIME is “Multi-purpose Internet Mail Extensions”.
It is extension of e-mail protocol helps to exchanges the different kids of data files (like audio, video, images, application programs and ASCII etc) over the internet.
Question9: what is the use of session_set_save_handler() in php?
Answer: session_set_save_handler() is used to save the session data into database.
2 3 4 |
session_set_save_handler ( 'openFunction' , 'closeFunction', 'readFunction' , 'writeFunction' , 'destroyFunction', 'gcFunction' ); |
There are the use of 6 callback functions which call automatically:
openFunction will be called automatically when session start.
closeFunction will be called automatically when session end.
readFunction will be called automatically when you read the session.
writeFunction will be called automatically when you write in the session.
destroyFunction will be called automatically when you destroy in the session.
gcFunction will be called automatically when session inactive for long time.
Question10: Why we use nl2br?
Answer: we used nl2br to insert the line break.
Question11: How to extract seconds, minutes and hour from date?
Answer:
2 3 4 5 6 7 8 |
$dateTime = strtotime("2016-09-30 12:25:60"); echo date('s',$dateTime); //seconds echo date('i',$dateTime); //Minutes echo date('h',$dateTime); //hour in 0-12 format echo date('H',$dateTime); //hour in 0-24 format |
Question12: How to convert object data to array?
Answer:
2 3 4 5 6 7 8 9 10 |
$obj = new stdClass(); $obj->key1 ='Val1'; $obj->key2 ='Val3'; $obj->key3 ='Val3'; $obj->key4 ='Val4'; $array = (Array)$obj; print_r($array);//Array ( [key1] => Val1 [key2] => Val3 [key3] => Val3 [key4] => Val4 ) |
Question13: How to create a folder if it doesn’t already exist?
Answer:
file_exists() is used to check directory exist OR NOT.
mkdir() is used to create the new directory.
2 3 4 5 6 7 |
$path="/path/dir"; if (!file_exists($path)) { mkdir($path, 0755, true); } |