How can I execute a PHP script using command line?
You can execute a PHP script by running the Command line interface program, in which you can enter the PHP script file as an argument.If the file is made for the web interface then it may not execute properly using command line. Command line allows faster execution of the statements and gives faster results.
How can we encrypt the password using PHP?
crypt() function is used to create one way encryption. It takes one input string and one optional parameter. The function look is defined as: crypt (input_string, salt), where input_string consists of the string which has to be encrypted and salt is an optional parameter. PHP uses DES for encryption. The format is as follows:-
<?php
$password = crypt('mypassword');
print $password . “ is the encrypted version of mypassword”;
?>
What are different types of Runtime Errors in PHP?
There are three types of Runtime Errors in PHP. They are as follows:-
- Notices: These are trivial, non-critical errors eg: undefined variable
- Warnings: These are serious errors eg. Including non-existing file
- Fatal errors: These are critical errors eg. Calling of non-existent function.
What does a special set of tags do in PHP?
Special set of tags allows you to display the output directly to the browser. The special set of tags are represented as
<?php..(your statements)..?>. They allow you to write your code for execution and representation, that you want to display and execute.
The example is as follows to explain it more:
<html>
<body>
<?php echo "Hello world"; ?> // it will print the Hello world directly to browser
</body>
</html>
Define urlencode() and urldecode() used in PHP?
urlencode() returns the URL encoded version of given string. For URL encoding string values are used in the queries to be passed as URL. Whereas,urldecode() returns the URL decoded string (original string) which will be decoded by taking the already encoded string.Example is as follows:
$discount ="10.00%";
$url = "http://domain.com/submit.php?disc=".urlencode($discount);
echo $url;
Output: "http://domain.com/submit.php?disc=10%2E00%25".
What is the difference between $message and $$message?
The only difference between $message and $$message is that, $message is a normal variable and $$message is variable to variable. The difference in functioning is shown below:
When declaring a variable in PHP the variable gets declared like this
$message //which is simply a variable
To store the data to assign the value to it we write like
$message= “ride”; //assigned the string to the variable
echo $message; // it will print the value
Whereas if you want to display the variable to variable then you use
$var="Hello";
$message="var";
echo $message; //print var
echo $$message; //print Hello.
What Is a Persistent Cookie?
Persistent cookie is a cookie which is permanently stored on user’s computer in a cookie
file. They are used for tracking the user information of the users who are browsing from a very long time. They also have the drawbacks of being unsecure, as user can see the cookies which are saved on the computer.
What is a PHP Session?
PHP session allows you to store the user session, like their information on server for faster access and for later use like username, IP addresses, their actions etc. The information which is saved is temporary and can be deleted after the user is no longer active. Example of starting a PHP session is as follows:
<?php
session_start(); // start up your PHP session!
?>
What is meant by PEAR in php? What is the purpose of it?
PEAR stands for "PHP Extension and Application Repository". As the name suggests, it gives advanced functionality to the PHP language and include many applications which can be used on fly. The purpose of it is as follows:-
- Open source structured library for PHP users
- Code distribution and package maintenance system
- Standard style for code written in PHP.
Is PHP a loosely Typed Language? What is the difference between strongly typed and loosely typed language?
Yes, PHP is a loosely typed language. In this type of language variable doesn’t need to be declared before their use. This language converts the data according to its given value. Whereas, in strongly typed language first every type has to be declared (defined) then only it can be used.
What do you mean by PEAR in PHP?
PEAR is a framework and distribution system for reusable PHP components.
What do you mean by Persistent Cookie?
A cookie which is stored in a cookie file permanently on the browser’s computer.
Differentiate between DROP a table and TRUNCATE a table.
DROP - It will delete the table and table data.
TRUNCATE - It will delete data of the table but not the table definition.
List the different run time errors in PHP.
a. Notices
b. Warnings
c. Fatal errors
Explain "GET" and "POST" methods.
Both the methods are used to send data to the server.
GET method - the browser appends the data onto the URL.
Post method - the data is sent as “standard input.”
Explain the "unlink" and "unset" functions.
unlink() function is for file system handling. It just deletes the file in context.
unset() function is for variable management. It makes a variable undefined
How will you change the name of a column in a table?
ALTER TABLE table_name CHANGE old_colm_name new_colm_name
What is the default session time in PHP?
Until closing the browser.
How will you create a database using PHP and MySQL?
By using : mysql_create_db("Database Name")
How will you find out the value of current session id?
By using: session_id()
$date1= strotime($start_date);
$date2= strotime($end_date);
$date_diff = (($date1)- ($date2)) / (60*60*24)
You can execute a PHP script by running the Command line interface program, in which you can enter the PHP script file as an argument.If the file is made for the web interface then it may not execute properly using command line. Command line allows faster execution of the statements and gives faster results.
How can we encrypt the password using PHP?
crypt() function is used to create one way encryption. It takes one input string and one optional parameter. The function look is defined as: crypt (input_string, salt), where input_string consists of the string which has to be encrypted and salt is an optional parameter. PHP uses DES for encryption. The format is as follows:-
<?php
$password = crypt('mypassword');
print $password . “ is the encrypted version of mypassword”;
?>
What are different types of Runtime Errors in PHP?
There are three types of Runtime Errors in PHP. They are as follows:-
- Notices: These are trivial, non-critical errors eg: undefined variable
- Warnings: These are serious errors eg. Including non-existing file
- Fatal errors: These are critical errors eg. Calling of non-existent function.
What does a special set of tags do in PHP?
Special set of tags allows you to display the output directly to the browser. The special set of tags are represented as
<?php..(your statements)..?>. They allow you to write your code for execution and representation, that you want to display and execute.
The example is as follows to explain it more:
<html>
<body>
<?php echo "Hello world"; ?> // it will print the Hello world directly to browser
</body>
</html>
Define urlencode() and urldecode() used in PHP?
urlencode() returns the URL encoded version of given string. For URL encoding string values are used in the queries to be passed as URL. Whereas,urldecode() returns the URL decoded string (original string) which will be decoded by taking the already encoded string.Example is as follows:
$discount ="10.00%";
$url = "http://domain.com/submit.php?disc=".urlencode($discount);
echo $url;
Output: "http://domain.com/submit.php?disc=10%2E00%25".
What is the difference between $message and $$message?
The only difference between $message and $$message is that, $message is a normal variable and $$message is variable to variable. The difference in functioning is shown below:
When declaring a variable in PHP the variable gets declared like this
$message //which is simply a variable
To store the data to assign the value to it we write like
$message= “ride”; //assigned the string to the variable
echo $message; // it will print the value
Whereas if you want to display the variable to variable then you use
$var="Hello";
$message="var";
echo $message; //print var
echo $$message; //print Hello.
What Is a Persistent Cookie?
Persistent cookie is a cookie which is permanently stored on user’s computer in a cookie
file. They are used for tracking the user information of the users who are browsing from a very long time. They also have the drawbacks of being unsecure, as user can see the cookies which are saved on the computer.
What is a PHP Session?
PHP session allows you to store the user session, like their information on server for faster access and for later use like username, IP addresses, their actions etc. The information which is saved is temporary and can be deleted after the user is no longer active. Example of starting a PHP session is as follows:
<?php
session_start(); // start up your PHP session!
?>
What is meant by PEAR in php? What is the purpose of it?
PEAR stands for "PHP Extension and Application Repository". As the name suggests, it gives advanced functionality to the PHP language and include many applications which can be used on fly. The purpose of it is as follows:-
- Open source structured library for PHP users
- Code distribution and package maintenance system
- Standard style for code written in PHP.
Is PHP a loosely Typed Language? What is the difference between strongly typed and loosely typed language?
Yes, PHP is a loosely typed language. In this type of language variable doesn’t need to be declared before their use. This language converts the data according to its given value. Whereas, in strongly typed language first every type has to be declared (defined) then only it can be used.
What do you mean by PEAR in PHP?
PEAR is a framework and distribution system for reusable PHP components.
What do you mean by Persistent Cookie?
A cookie which is stored in a cookie file permanently on the browser’s computer.
Differentiate between DROP a table and TRUNCATE a table.
DROP - It will delete the table and table data.
TRUNCATE - It will delete data of the table but not the table definition.
List the different run time errors in PHP.
a. Notices
b. Warnings
c. Fatal errors
Explain "GET" and "POST" methods.
Both the methods are used to send data to the server.
GET method - the browser appends the data onto the URL.
Post method - the data is sent as “standard input.”
Explain the "unlink" and "unset" functions.
unlink() function is for file system handling. It just deletes the file in context.
unset() function is for variable management. It makes a variable undefined
How will you change the name of a column in a table?
ALTER TABLE table_name CHANGE old_colm_name new_colm_name
What is the default session time in PHP?
Until closing the browser.
How will you create a database using PHP and MySQL?
By using : mysql_create_db("Database Name")
How will you find out the value of current session id?
By using: session_id()
Explain how to execute a PHP script using command line. PHP script using command line can be executed using SAPI (Server Application programming Interface). Using SAPI Command Line Interface the PHP code can be passed to execute directly.Example: Php –r ‘print_r(get_defined_constanrs());’
From a shell, php –v will display whether the SAPI is CLI or CGI
How can we increase the execution time of a PHP script?
By default the PHP script takes 30secs to execute. This time is set in the php.ini file. This time can be increased by modifying the max_execution_time in seconds. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.Explain the purpose of output buffering in PHP.
Output buffering in PHP buffers a scripts output. This buffer can be edited before returning it to the client. Without output buffering, PHP sends data to the web server as soon as it is ready. Output buffering "send" cookies at any point in the script. Cookies do not have to be necessarily sent near the start of page. Output buffers are stackable and hence sending to output is by choice.
Describe session in PHP.
When a user logs in an application, his details are usually stored in a session variable. This information is available to all pages in one application. Sessions in PHP work using a unique id for each visitor.
How can we know the number of days between two given dates using PHP?
The start date and end date can be first found as shown below:$date1= strotime($start_date);
$date2= strotime($end_date);
$date_diff = (($date1)- ($date2)) / (60*60*24)