Saturday, 9 April 2016

PHP Interview Question?

What is PHP?

-->PHP is a web language based on scripts that allows developers to dynamically create generated web pages.

What does the initials of PHP stand for?

-->PHP means PHP: Hypertext Preprocessor.

Which programming language does PHP resemble to?

-->PHP syntax resembles Perl and C.

What does PEAR stands for?

PEAR means “PHP Extension and Application Repository”. it extends PHP and provides a higher level of programming for web developers.’

What is the latest PHP version?

PHP 7 .
How do you execute a PHP script from the command line?

Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:
Copy con index.php
CTRL+Z+ENTER
Save file
To run file - php script.php

How to run the interactive PHP shell from the command line interface?

Just use the PHP CLI program with the option -a as follows:
php -a
interactive mode enabled
<?php
echo "hello there world!";
phpinfo();
?>
^Z
hit enter)
hello there world!
phpinfo....

What are the correct and the most two common way to start and finish a PHP block of code?

The two most  common ways to start and finish a PHP script are: <?php [   —  PHP code—- ] ?> and <? [—  PHP code  —] ?>

How can we display the output directly to the browser?

To be able to display the output directly to the browser, we have to use the special tags <?= and ?>.

What is the main difference between PHP 4 and PHP 5 OR Above Versions?


PHP 5 presents many additional OOP (Object Oriented Programming) features.

What are PHP magic constants?
PHP provides a large number of predefined constants to any script which it runs.
A few "magical" PHP constants given below −

  • __LINE__                 : The current line number of the file
  • __FILE__                 : The full path and filename of the file
  • __DIR__                   : This prints file full path, without file name
  • __FUNCTION__     : The function name
  • __CLASS__             :  The class name
  • __METHOD__        : The class method name
Example of __LINE__  :

<?php 
// This prints current line number on file
echo "This is line number " . __LINE__ . ".\n";
?>
Example of __FILE__   :
<?php 
 echo "This file full path and file name is '" . __FILE__ . "<br/>";
?>
Example of __DIR__     
:
<?php 
// This prints file full path, without file name
        echo "This file full path is '" . __DIR__ . "'.\n";
?>
Example of __FUNCTION__ 
 :
<?php 
// Really simple basic test function
 function test_function_magic_constant() {
 echo "This is from '" . __FUNCTION__ . "' function.\n";
 }
?>
Example of __CLASS__
 :
<?php 
 // Really simple class for testing magic constants
 class TestMagicConstants {
 // Prints class name
 public function printClassName() {
 echo "This is " . __CLASS__ . " class.\n";
 }
?>
Example of __METHOD__  :
<?php 
// Prints class and method name
 public function printMethodName() {
 echo "This is " . __METHOD__ . " method.\n";
 }
?>
What is the purpose of break statement?

A break statement are used to break to terminated any loop in php.
Example:

<?php
for($i=0;$i<30;$i++)
{
if($i==5){
break;
}
echo $i. "<br/>";
}
How will you get the browser's details using PHP?
<?php
echo $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser();
print_r($browser);
?>
How will you concatenate two strings in PHP?
Using Dot(.) Operator.

0 comments:

Post a Comment