• +91 9971497814
  • info@interviewmaterial.com

PHP Interview Questions Answers

Question 1 : What type of headers have to be added in the mail function to attach a file?

Answer 1 : $boundary = '--' . md5( uniqid ( rand() ) ); $headers = "From: \"Me\"\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";

Question 2 : What’s the output of the ucwords function in this example?

Answer 2 : $formatted = ucwords("TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS"); print $formatted; What will be printed is TECHPREPARATIONS 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.

Question 3 : How can we get second of the current time using date function?

Answer 3 : $second = date("s");

Question 4 : How can we extract string "abc.com" from a string "mailto:info@abc.com?subject=Feedback" using regular expression of PHP?

Answer 4 : $text = "mailto:info@abc.com?subject=Feedback"; preg_match('|.*@([^?]*)|', $text, $output); echo $output[1]; Note that the second index of $output, $output[1], gives the match, not the first one, $output[0].

Question 5 : How can we extract string 'abc.com ' from a string http://info@abc.com using regular expression of php?

Answer 5 :  We can use the preg_match() function with "/.*@(.*)$/" as the regular expression pattern. For example: preg_match("/.*@(.*)$/","http://info@abc.com",$data); echo $data[1];

Question 6 : What’s the difference between accessing a class method via -> and via ::?

Answer 6 : :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.

Question 7 : What’s the special meaning of __sleep and __wakeup?

Answer 7 : __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

Question 8 : What is the difference between $message and $$message?

Answer 8 : 1) - $message is a simple variable whereas $$message is a reference variable. Example: $user = 'bob' is equivalent to $holder = 'user'; $$holder = 'bob'; 2) - They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.

Question 9 : How can I know that a variable is a number or not using a JavaScript?

Answer 9 : 1) - bool is_numeric( mixed var) Returns TRUE if var is a number or a numeric string, FALSE otherwise. 2)- Definition and Usage The isNaN() function is used to check if a value is not a number. Syntax isNaN(number) Parameter Description number Required. The value to be tested

Question 10 : HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT?

Answer 10 : 1) - Create a full backup of your database: shell> mysqldump tab=/path/to/some/dir opt db_name Or: shell> mysqlhotcopy db_name /path/to/some/dir The full backup file is just a set of SQL statements, so restoring it is very easy: shell> mysql "."Executed"; To backup: BACKUP TABLE tbl_name TO /path/to/backup/directory ’ To restore: RESTORE TABLE tbl_name FROM /path/to/backup/directory mysqldump: Dumping Table Structure and Data Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table. -t, no-create-info Don't write table creation information (the CREATE TABLE statement). -d, no-data Don't write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!

PHP Contributors

krishan

Share your email for latest updates

Name:
Email:

Our partners