Q:1 | What are the differences between Get and post methods in form submitting.
| ||||||||||||||||||||
A:1 | When to use GET or POST The HTML 2.0 specification says, in section Form
–>If the processing of a form is idempotent
How the form data is transmitted? quotation from the HTML 4.0 specification –> If the method is “get” - -, the user agent
Quote from CGI FAQ Firstly, the the HTTP protocol specifies
This is a theoretical point which is also good
GET is (in theory) the preferred method for
I would prefer POST when I don’t want the status to
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:2 | Who is the father of PHP and explain the changes in PHP versions? | ||||||||||||||||||||
A:2 | Rasmus Lerdorf is known as the father of PHP.PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:3 | How can we submit a form without a submit button? | ||||||||||||||||||||
A:3 | The main idea behind this is to use Java script submit() function in
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:4 | In how many ways we can retrieve the data in the result set of
| ||||||||||||||||||||
A:4 | You can do it by 4 Ways1. mysql_fetch_row.
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:5 | What is the difference between mysql_fetch_object and
| ||||||||||||||||||||
A:5 | mysql_fetch_object() is similar tomysql_fetch_array(), with one difference -
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:6 | What is the difference between $message and $$message? | ||||||||||||||||||||
A:6 | It is a classic example of PHP’s variable variables. take the
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:7 | How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’
| ||||||||||||||||||||
A:7 | preg_match(”/^http:\/\/.+@(.+)$/”,’http://info@abc.com’,$found);
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:8 | How can we create a database using PHP and MySQL? | ||||||||||||||||||||
A:8 | We can create MySQL database with the use of
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:9 | What are the differences between require and include,
| ||||||||||||||||||||
A:9 | The include() statement includes
The include_once()
require_once()
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:10 | Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”? | ||||||||||||||||||||
A:10 | Yes we can use include() more than one time in any page though it is
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:11 | What are the different tables present in MySQL, which type of
| ||||||||||||||||||||
A:11 | Total 5 types of tables we can create
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:12 | Functions in IMAP, POP3 AND LDAP? | ||||||||||||||||||||
A:12 | You can find these specific information in PHP Manual. | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:13 | How can I execute a PHP script using command line? | ||||||||||||||||||||
A:13 | As of version 4.3.0, PHP supports a new SAPI type (Server
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:14 | Suppose your Zend engine supports the mode Then how can u
| ||||||||||||||||||||
A:14 | In php.ini file:
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:15 | Shopping cart online validation i.e. how can we configure Paypal,
| ||||||||||||||||||||
A:15 | We can find the detail documentation about different paypal
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:16 | What is meant by nl2br()? | ||||||||||||||||||||
A:16 | Inserts HTML line breaks (
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:17 | Draw the architecture of Zend engine? | ||||||||||||||||||||
A:17 | The Zend Engine is the internal compiler and runtime engine used by
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:18 | What are the current versions of apache, PHP, and MySQL? | ||||||||||||||||||||
A:18 | As of February, 2007 the current versions arePHP: php5.2.1
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:19 | What are the reasons for selecting lamp (Linux, apache, MySQL,
| ||||||||||||||||||||
A:19 | All of those are open source resource. Security of Linux is very
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:20 | How can we encrypt and decrypt a data present in a MySQL table
| ||||||||||||||||||||
A:20 | AES_ENCRYPT () and AES_DECRYPT () | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:21 | How can we encrypt the username and password using PHP? | ||||||||||||||||||||
A:21 | The functions in this section perform encryption and decryption, and
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:22 | What are the features and advantages of object-oriented
| ||||||||||||||||||||
A:22 | One of the main advantages of OO programming is its ease of
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:23 | What are the differences between procedure-oriented languages and
| ||||||||||||||||||||
A:23 | Traditional programming has the following characteristics:Functions are written sequentially, so that a change in programming can
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:24 | What is the use of friend function? | ||||||||||||||||||||
A:24 | Sometimes a function is best shared among a number of different
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:25 | What are the differences between public, private, protected,
| ||||||||||||||||||||
A:25 | Public: Public declared items can be accessed everywhere.
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:26 | What are the different types of errors in PHP? | ||||||||||||||||||||
A:26 | Three are three types of errors:1. Notices: These are trivial,
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:27 | What is the functionality of the function strstr and stristr? | ||||||||||||||||||||
A:27 | strstr: Returns part of haystack
If needle is not a
This function is case-sensitive. For
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:28 | What are the differences between PHP 3 and PHP 4 and PHP 5? | ||||||||||||||||||||
A:28 | Please read the release notes at
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:29 | How can we convert asp pages to PHP pages? | ||||||||||||||||||||
A:29 | there are lots of tools available for asp to PHP conversion. you can
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:30 | What is the functionality of the function htmlentities? | ||||||||||||||||||||
A:30 | Convert all applicable characters to HTML entities
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:31 | How can we get second of the current time using date function? | ||||||||||||||||||||
A:31 | $second = date(”s”); | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:32 | How can we convert the time zones using PHP? | ||||||||||||||||||||
A:32 | By using date_default_timezone_get and
// Discover what 8am in Tokyo relates to on the East Coast of the US
// Set the default timezone to Tokyo time: date_default_timezone_set('Asia/Tokyo');
// Now generate the timestamp for that particular timezone, on Jan 1st, 2000 $stamp = mktime(8, 0, 0, 1, 1, 2000);
// Now set the timezone back to US/Eastern date_default_timezone_set('US/Eastern');
// Output the date in a standard format (RFC1123), this will print: // Fri, 31 Dec 1999 18:00:00 EST echo ' | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:33 | What is meant by urlencode and urldocode? | ||||||||||||||||||||
A:33 | URLencode returns a string in which all non-alphanumeric characters
urldecode decodes any %##
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:34 | What is the difference between the functions unlink and unset? | ||||||||||||||||||||
A:34 | unlink() deletes the given file from the file system.
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:35 | How can we register the variables into a session? | ||||||||||||||||||||
A:35 | $_SESSION[’name’] = “Mizan”; | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:36 | How can we get the properties (size, type, width, height) of an
| ||||||||||||||||||||
A:36 | To know the Image type use exif_imagetype () function
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:37 | How can we get the browser properties using PHP? | ||||||||||||||||||||
A:37 | By using
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:38 | What is the maximum size of a file that can be uploaded using PHP
| ||||||||||||||||||||
A:38 | By default the maximum size is 2MB. and we can change the following
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:39 | How can we increase the execution time of a PHP script? | ||||||||||||||||||||
A:39 | by changing the following setup at php.inimax_execution_time = 30
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:40 | How can we take a backup of a MySQL table and how can we restore
| ||||||||||||||||||||
A:40 | To backup: BACKUP TABLE tbl_name[,tbl_name…] TO
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:41 | How can we optimize or increase the speed of a MySQL select
| ||||||||||||||||||||
A:41 |
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:42 | How many ways can we get the value of current session id? | ||||||||||||||||||||
A:42 | session_id() returns the session id for the current session. | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:43 | How can we destroy the session, how can we unset the variable of
| ||||||||||||||||||||
A:43 | session_unregister — Unregister a global variable from the current
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:44 | How can we destroy the cookie? | ||||||||||||||||||||
A:44 | Set the cookie in past. | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:45 | How many ways we can pass the variable through the navigation
| ||||||||||||||||||||
A:45 |
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:46 | What is the difference between ereg_replace() and eregi_replace()? | ||||||||||||||||||||
A:46 | eregi_replace() function is identical to ereg_replace() except that
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:47 | What are the different functions in sorting an array? | ||||||||||||||||||||
A:47 | Sort(), arsort(),
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:48 | How can we know the count/number of elements of an array? | ||||||||||||||||||||
A:48 | 2 ways
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:49 | What is the PHP predefined variable that tells the What types of
| ||||||||||||||||||||
A:49 | Though i am not sure if this is wrong or not, With the exif
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:50 | How can I know that a variable is a number or not using a
| ||||||||||||||||||||
A:50 | bool is_numeric ( mixed var)
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:51 | List out some tools through which we can draw E-R diagrams for
| ||||||||||||||||||||
A:51 | Case Studio
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:52 | How can I retrieve values from one database server and store them
| ||||||||||||||||||||
A:52 | we can always fetch from one database and rewrite to another. here
take a look below.
$db2 = mysql_connect(”host”,”user”,”pwd”, true)
So mysql_connect has another optional boolean parameter which
now the following query will execute successfully.
Thanks goes to Hasan and Hasin for this solution. | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:53 | List out the predefined classes in PHP? | ||||||||||||||||||||
A:53 | Directory
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:54 | How can I make a script that can be bi-language (supports
| ||||||||||||||||||||
A:54 | You can maintain two separate language file for each of the
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:55 | What are the difference between abstract class and interface? | ||||||||||||||||||||
A:55 | Abstract class: abstract classes are the class where one or more
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:56 | How can we send mail using JavaScript? | ||||||||||||||||||||
A:56 | JavaScript does not have any networking capabilities as it is
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:57 | How can we repair a MySQL table? | ||||||||||||||||||||
A:57 | The syntex for repairing a MySQL table is
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:58 | What are the advantages of stored procedures, triggers, indexes? | ||||||||||||||||||||
A:58 | A stored procedure is a set of SQL commands that can be compiled and
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:59 | What is the maximum length of a table name, database name, and
| ||||||||||||||||||||
A:59 | The following table describes the maximum length for each type of
There are some restrictions on the characters that may appear in
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:60 | How many values can the SET function of MySQL take? | ||||||||||||||||||||
A:60 | MySQL set can take zero or more values but at the maximum it can
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:61 | What are the other commands to know the structure of table using
| ||||||||||||||||||||
A:61 | describe Table-Name; | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:62 | How many tables will create when we create table, what are they? | ||||||||||||||||||||
A:62 | The ‘.frm’ file stores the table definition.
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:63 | What is the purpose of the following files having extensions 1) .frm
| ||||||||||||||||||||
A:63 | In MySql, the default table type is MyISAM.
m’ file stores the table definition.
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:64 | What is maximum size of a database in MySQL? | ||||||||||||||||||||
A:64 | If the operating system or filesystem places a limit on the number
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:65 | Give the syntax of Grant and Revoke commands? | ||||||||||||||||||||
A:65 | The generic syntax for grant is as following
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:66 | Explain Normalization concept? | ||||||||||||||||||||
A:66 | The normalization process involves getting our data to conform to
I have a confession to make; I do not often use Third Normal Form. In
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:67 | How can we find the number of rows in a table using MySQL? | ||||||||||||||||||||
A:67 | Use this for mysql
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:68 | How can we find the number of rows in a result set using PHP? | ||||||||||||||||||||
A:68 |
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:69 | How many ways we can we find the current date using MySQL? | ||||||||||||||||||||
A:69 | SELECT CURDATE();
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:70 | What are the advantages and disadvantages of Cascading Style
| ||||||||||||||||||||
A:70 | External Style SheetsAdvantagesCan control styles for multiple documents at once. Classes can be
Advantages Classes can be created for use on multiple tag types in the document.
Disadvantages This method can not control styles for multiple documents at once Inline Styles Advantages Useful for small quantities of style definitions. Can override other
Disadvantages Does not distance style information from content (a main goal of
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:71 | What type of inheritance that PHP supports? | ||||||||||||||||||||
A:71 | In PHP an extended class is always dependent on a single base class,
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:72 | What is the difference between Primary Key and
| ||||||||||||||||||||
A:72 | Primary Key: A column in a table whose values uniquely identify the
Unique Key: Unique Keys are used to uniquely identify each row in the
| ||||||||||||||||||||
| | ||||||||||||||||||||
| The structure of table view buyers is as follows:
the value of user_pri_id the last row 999 then What will happen in
Condition1: Delete all the rows and insert another row then.
| ||||||||||||||||||||
A:73 | In both cases let the value for auto increment field be n then next
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:74 | What are the advantages/disadvantages of MySQL and PHP? | ||||||||||||||||||||
A:74 | Both of them are open source software (so free of cost), support
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:75 | What is the difference between GROUP BY and ORDER BY in Sql? | ||||||||||||||||||||
A:75 | ORDER BY [col1],[col2],…,[coln]; Tels DBMS according to what columns
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:76 | What is the difference between char and varchar data types? | ||||||||||||||||||||
A:76 | Set char to occupy n bytes and it will take n bytes even if u r
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:77 | What is the functionality of md5 function in PHP? | ||||||||||||||||||||
A:77 | Calculate the md5 hash of a string. The hash is a 32-character
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:78 | How can I load data from a text file into a table? | ||||||||||||||||||||
A:78 | you can use LOAD DATA INFILE file_name; syntax to load data
| ||||||||||||||||||||
| | ||||||||||||||||||||
Q:79 | How can we know the number of days between two given dates using
| ||||||||||||||||||||
A:79 | SELECT DATEDIFF(’2007-03-07′,’2005-01-01′); | ||||||||||||||||||||
| | ||||||||||||||||||||
Q:80 | How can we know the number of days between two given dates using
| ||||||||||||||||||||
A:80 | $date1 = date(’Y-m-d’);
|
- What does a special set of tags do in PHP? - The output is displayed directly to the browser.
- What’s the difference between include and require? - It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
- 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.
- 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.
- How do you define a constant? - Via define() directive, like define ("MYCONSTANT", 100);
- How do you pass a variable by value? - Just like in C++, put an ampersand in front of it, like $a = &$b
- Will comparison of string "10" and integer 11 work in PHP? - Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.
- When are you supposed to use endif to end the conditional statement? - When the original if was followed by : and then the code block without braces.
- Explain the ternary conditional operator in PHP? - Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.
- How do I find out the number of parameters passed into function? - func_num_args() function returns the number of parameters passed in.
- If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? - 100, it’s a reference to existing variable.
- What’s the difference between accessing a class method via -> and via ::? - :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.
- Are objects passed by value or by reference? - Everything is passed by value.
- How do you call a constructor for a parent class? - parent::constructor($value)
- What’s the special meaning of __sleep and __wakeup? - __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.
- Why doesn’t the following code print the newline properly? $str = ‘Hello, there.\nHow are you?\nThanks for visiting TechInterviews’;
print $str;
?>
Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n. - Would you initialize your strings with single quotes or double quotes? - Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.
- How come the code works, but doesn’t for two-dimensional array of mine? - Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.
- What is the difference between characters \023 and \x23? - The first one is octal 23, the second is hex 23.
- With a heredoc syntax, do I get variable substitution inside the heredoc contents? - Yes.
- I want to combine two variables together:
22. $var1 = 'Welcome to ';
23. $var2 = 'TechInterviews.com';
What will work faster? Code sample 1:
$var 3 = $var1.$var2;
Or code sample 2:
$var3 = "$var1$var2";
Both examples would provide the same result - $var3 equal to "Welcome to TechInterviews.com". However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.
- For printing out strings, there are echo, print and printf. Explain the differences. - echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:
and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.
- I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP? - On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().
- What’s the output of the ucwords function in this example?
27. $formatted = ucwords("TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS");
print $formatted;
What will be printed is TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS.
ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.
- What’s the difference between htmlentities() and htmlspecialchars()? - htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
- What’s the difference between md5(), crc32() and sha1() crypto on PHP? - The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.
- So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()? - Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.
- How do you match the character ^ at the beginning of the string? - ^\^
No comments:
Post a Comment