PHP Interview Questions and Answers – Part 7

111. What is meant by urlencode and urldecode?
urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode(“10.00%”) will return “10%2E00%25″. URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string.
string urlencode(str) – Returns the URL encoded version of the input string. String values to be used in URL query string need to be URL encoded. In the URL encoded version:
Alphanumeric characters are maintained as is.
Space characters are converted to “+” characters.
Other non-alphanumeric characters are converted “%” followed by two hex digits representing the converted character.
string urldecode(str) – Returns the original string of the input URL encoded string.
For example:
$discount =”10.00%”;
$url = “”.urlencode($discount);
echo $url;You will get “″.

112. How To Get the Uploaded File Information in the Receiving Script?
Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:$_FILES[$fieldName][‘name’] – The Original file name on the browser system.$_FILES[$fieldName][‘type’] – The file type determined by the browser.
$_FILES[$fieldName][‘size’] – The Number of bytes of the file content.
$_FILES[$fieldName][‘tmp_name’] – The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[$fieldName][‘error’] – The error code associated with this file upload.
The $fieldName is the name used in the .

113. What is the difference between mysql_fetch_object and mysql_fetch_array?
MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array

114. How can I execute a PHP script using command line?
Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

115. I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.

116. Would I use print “$a dollars” or “{$a} dollars” to print out the amount of dollars in this example?
In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like “{$a},000,000 mln dollars”, then you definitely need to use the braces.

117. What are the different tables present in MySQL? Which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10))?
Total 5 types of tables we can create
1. MyISAM2. Heap
3. Merge
MyISAM is the default storage engine as of MySQL 3.23. When you fire the above create query MySQL will create a MyISAM table.

118. How To Create a Table?
If you want to create a table, you can run the CREATE TABLE statement as shown in the following sample script:
Remember that mysql_query() returns TRUE/FALSE on CREATE statements. If you run this script, you will get something like this:
Table Tech_links created.

119. How can we encrypt the username and password using PHP?
You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD(“Password”);
You can also use the MySQL PASSWORD() function to encrypt username and password. For example,
INSERT into user (password, …) VALUES (PASSWORD($password”)), …);

Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)

Leave a Reply

Your email address will not be published. Required fields are marked *

six − 4 =

Popup Dialog Box Powered By :
  • RSS
  • Facebook
  • Google+
  • Twitter