Interview Questions on PHP
1. What is PHP?
PHP(Hypertext Pre Processor) :- PHP is server side programming language that is used to develop the web applications and can be easily embed with HTML code.
2. How to write HTML code in PHP?
1. By using echo :-
This text visible in browser ”;
2. Write html code out side php context :-
// php codde goes here
<!--write HTML code here -->
<div> text message </div>
//php code goes here
3. How to declare and initialize variables?
variable starts with the $ sign, followed by the name of the variable.
Syntax :- $variable_name = value;
Ex :- $name = “ramesh”;
4. What is the difference b/w $var and $$var?
Below example describes difference b/w $ and $$
$var1 = msg;
$$var1 = “value1”; // equalent to $msg = “value1”;
o/p :- value1
5. How to write comments in PHP?
1. Single line comment :- starts with // followed by comments.
2. Multi line comment :-
Multiline comments starts with /* and ends with */
/* Comment line 1
Comment line 2
Comment line 3
6. How to redirect to another web page in php?
7. What is cookie?
Cookie :- Cookie is a variable that stores data in browser to manage web applications.
8. How to create cookie?
Create Cookie :- use setcookie()
Synatax :- setcookie($cookie_name, $cookie_value,expirytime);
Ex :- setcookie($cookie1, “456”, time() + (86400 * 30), "/");
here "/" means that the cookie is available in entire website.
9. How to destroy the cookie?
setcookie('cookie_name', null, -1, '/');
10. What is session variable?
Session Variable :-
Session variable is used to store values to maintain the web applications.
Session variable is created by created and maintained by browser.