1. What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?
get is like query string all the variables will be displayed in he url
where as post is the standard way of sending th evariables
When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn’t display these values.
2. Who is the father of PHP and explain the changes in PHP versions?
Father of php is Rasmus Lerdorf
3. What is the difference between $message and $$message?
$message is variable whereas $$message is Dynamic variable.
eg.
$user=”bob”
is equivalent to
$holder=”user”;
$$holder=”bob”;
4. How can we create a database using PHP and mysql?
mysql_create_db() should work
5. Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?
Yes we can include that many times we want, but here are some things to make sure of:
(including abc.PHP, the file names are case-sensitive)
there shouldnt be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php
6. How can I execute a PHP script using command line?
Through php parse you can execute PHP script using command line. By default location of php parser is /var/www/html so set the path of this directory and just use as following
7. Suppose your Zend engine supports the mode <? ?> Then how can u configure your PHP Zend engine to support <?PHP ?> mode ?
In php.ini file:
set short_open_tag=on to make PHP support
8. What is meant by nl2br()?
nl2br() inserts html in string. echo nl2br(”god bless \n you”);
output
god bless
you
9. What are the different types of errors in PHP?
Three are three types of errors 1) Fatal errors 2) Parser errors 3) Startup errors.
10. What is meant by urlencode and urldocode?
string urlencode(str)
where str contains a string like this “hello world” and the return value will be URL encoded and can be use to append with URLs, normaly used to appned data for GET like someurl.com?var=hello%world
string urldocode(str)
this will simple decode the GET variable’s value
Like it echo (urldecode($_GET_VARS[var])) will o/p “Hello world”
11. List out the predefined classes in PHP?
Predefined Classes
1. Standard Defined Classes
These classes are defined in the standard set of functions included in the PHP build.
a. Directory
The class from which dir() is instantiated.
b.stdClass
2.Ming Defined Classes
These classes are defined in the Ming extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.
a.swfshape b. swffill c. swfgradient d. swfbitmap e. swftext f. swftextfield
g. swffont h. swfdisplayitem i. swfmovie j. swfbutton k. swfaction
l. swfmorph m. swfsprite
3. Oracle 8 Defined Classes
These classes are defined in the Oracle 8 extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.
a. OCI-Lob b. OCI-Collection
4. qtdom Defined Classes
These classes are defined in the qtdom extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.
a. QDomDocument b. QDomNode
12. If you have to work with dates in the following format: “Tuesday, February 14, 2006 @ 10:39 am”, how can you convert them to another format, that is easier to use?
The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.
So let’s say we have
$date = “Tuesday, February 14, 2006 @ 10:39 am”;
In order to convert that to a timestamp, we need to get rid of the “@” sign, and we can use the remaining string as a parameter for the strtotime function.
So we have
$date = str_replace(“@ “,””,$date);
$date = strtotime($date);
now $date is a timestamp
and we can say:
echo date(“d M Y”,$date);
13. How we know browser properties?
get_browser() attempts to determine the capabilities of the user’s browser. This is done by looking up the browser’s information in the browscap.ini file.
echo $_SERVER[‘HTTP_USER_AGENT’] . “\n”;
$browser = get_browser();
foreach ($browser as $name => $value) {
echo “$name $value
\n”;
}
14. How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)?
For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.
15. How i can get ip address?
We can use SERVER var $_SERVER[‘SERVER_ADDR’] and getenv(“REMOTE_ADDR”) functions to get the IP address.