Breaking

Followers

Tuesday, 11 October 2016

Top PHP Interview Questions And Answers

1. How can we encrypt password using PHP?
crypt () function is used to create one way encryption. It takes one input string and one optional parameter. The function is defined as: crypt (input_string, salt), where input_string consists of the string that has to be encrypted and salt is an optional parameter. PHP uses DES for encryption. The format is as follows:
php code
2. Explain how to submit a Form without a submit button.
A form can be posted or submitted without the button in the following ways:
1. On OnClick event of a label in the form, a JavaScript function can be called to submit the form.
Example:
               document.form_name.submit()
2. Using a Hyperlink: On clicking the link, JavaScript function can be called.
Example:
Q5 php IQA code
A form can be submitted in these other ways without using submit button.
• Submitting a form by clicking a link
• Submitting a form by selecting an option from drop down box with the invocation of onChange event
• Using java script : document.form.submit();
• Using header(“location:page.php”);
3. How can we increase the execution time of a PHP script?
• Default time allowed for the PHP scripts to execute is 30 secs mentioned in the php.inifile. The function used is set_time_limit(int sec). If the value passed is ‘0’, it takes unlimited time. It should be noted that if the default timer is set to 30 sec, and 20 sec is specified in set_time_limit(), the script will run for 45 seconds.
• This time can be increased by modifying the max_execution_time in secs. 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.
• The script execution time can be increased by
– Using sleep() function in PHP script
– Using set_time_limit() function
– The default limit is 30 seconds. The time limit can be set to zero to impose no time limit to pause.
4. What is Zend Engine?
• Zend Engine is used internally by PHP as a compiler and runtime engine. PHP Scripts are loaded into memory and compiled into Zend opcodes.
• These opcodes are executed and the HTML generated is sent to the client.
• The Zend Engine provides memory and resource management, and other standard services for the PHP language. Its performance, reliability and extensibility played a significant role in PHP’s increasing popularity.
5. What library is used for pdf in PHP?
The PDF functions in PHP can create PDF files using the PDFlib library Version 6. PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4.
There is also the » Panda module. FPDF is a PHP class, which allows generating PDF files with pure PHP (without using the PDFlib library.)
F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.
6. What are some new features introduced in PHP7?
1. Zend Engine 3 performance improvements and 64-bit integer support on Windows
2. uniform variable syntax AST-based compilation process
3. added Closure::call()
4. bitwise shift consistency across platforms
5. (null coalesce) operator
6. Unicode codepoint escape syntax
7. return type declarations
8. and scalar type (integer, float, string and boolean) declarations.
7. What is htaccess? Why do we use this and where?
• htaccess files are configuration files of Apache Server that provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
• These .htaccess files are used to change the functionality and features of Apache web server.
For instance, htaccess file is used for url rewrite.
–> It is used to make the site password protected.
–> .htaccess file can restrict some ip addresses so that on restricted ip addresses, the site will not open.
8. What are magic methods?
• Magic methods are member functions that are available to all the instance of class. Magic methods always start with “__”. Eg. __construct.
• All magic methods need to be declared as public
• To use a method, it should be defined within the class or program scope
• Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone().
9. What is meant by PEAR in PHP?
PEAR is an acronym for “PHP Extension and Application Repository” The purpose of PEAR is to provide:
• A structured library of open-sourced code for PHP users
• A system for code distribution and package maintenance
• A standard style for writing code in PHP
• PHP Foundation Classes (PFC)
• PHP Extension Community Library (PECL)
• A website, mailing lists and download mirrors to support the PHP/PEAR community
10. Explain soundex() and metaphone().
soundex()
The soundex() function calculates the soundex key of a string. A soundex key is a four character long alphanumeric strings that represents English pronunciation of a word. The soundex() function can be used for spelling applications.
$str= “hello”;
Echo soundex($str);
?>
metaphone()
the metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if pronounced by an English person. This function can also be used for spelling applications.
echo metaphone(“world”);
?>
11. What is smarty?
Smarty is a template engine written in PHP. Typically, these templates will include variables —like {$variable} — and a range of logical and loop operators to allow adaptability within of the template.
12. What is Memcache?
Memcache is a technology that caches objects in memory such that your web application can get to them really fast. It is used by sites such as Digg.com, Facebook.com and NowPublic.com and is widely recognized as an essential ingredient in scaling any LAMP.
13. How can we 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.
• Remember that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

No comments:

Post a Comment