PHP

{"iq":[{"id":"1",
    "q":"What is PHP?",
    "answer":"PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.\nEven a non technical person can cretae sites using its CMS.\nWordPress,osCommerce are the famus CMS of php.\nIt is also an object oriented programming language like java,C-sharp etc.It is very eazy for learning  "
  },
    {"id":"2",
      "q":"What is the use of \"echo\" in php? ",
      "answer":"It is used to print a data in the webpage, Example: <?php echo 'Car insurance'; ?> ,\nThe following code print the text in the webpage "
    },
    {"id":"3",
      "q":"How to include a file to a php page?",
      "answer":"We can include a file using \"include()\" or \"require()\" function with file path as its parameter."
    },

    {"id":"4",
      "q":"What's the difference between include and require?",

      "answer":"If the file is not found by require(),\nit will cause a fatal error and halt the execution of the script.\nIf the file is not found by include(),\na warning will be issued, but execution will continue."
    },
    {"id":"5",
      "q":"require_once(), require(), include().What is difference between them? ",
      "answer":"require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).\nSo, require_once() is recommended to use when you want to include a file where you have a lot of functions for example.\nThis way you make sure you don't include the file more times and you will not get the \"function re-declared\" error."
    },
    {"id":"6",
      "q":"Differences between GET and POST methods ? ",
      "answer":"We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method . "
    },

    {"id":"7",
      "q":"How to declare an array in php?",
      "answer":"Eg : var $arr = array('apple', 'grape', 'lemon'); "
    },

    {"id":"8",
      "q":"What is the use of 'print' in php?",
      "answer":"This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.\nExample print('PHP Interview questions');\nprint 'Job Interview ');"
    },
    {"id":"9",
      "q":"What is use of in_array() function in php ? ",

      "answer":"in_array used to checks if a value exists in an array"
    },

    {"id":"10",
      "q":"What is use of count() function in php ?",
      "answer":"count() is used to count all elements in an array, or something in an object"
    },

    {"id":"11",
      "q":"What's the difference between include and require?",

      "answer":"It's how they handle failures. If the file is not found by require(),\nit will cause a fatal error and halt the execution of the script.\nIf the file is not found by include(), a warning will be issued, but execution will continue."
    },

    {"id":"12",
      "q":"What is the difference between Session and Cookie?",
      "answer":"The main difference between sessions and cookies is that sessions are stored on the server,and cookies are stored on the user's computers in the text file format.\nCookies can't hold multiple variable while session can hold multiple variables..\nWe can set expiry for a cookie,The session only remains active as long as the browser is open.\nUsers do not have access to the data you stored in Session,Since it is stored in the server.\nSession is mainly used for login/logout purpose while cookies using for user activity tracking"
    },
    {"id":"13",
      "q":"How to set cookies in PHP?",
      "answer":" Setcookie(\"sample\", \"ram\", time()+3600);"
    },

    {"id":"14",
      "q":"How to Retrieve a Cookie Value?",
      "answer":"eg : echo $_COOKIE[\"user\"];"
    },

    {"id":"15",
      "q":"what types of loops exist in php? ",
      "answer":" for,while,do while and foreach "
    },

    {"id":"16",
      "q":"How we can retrieve the data in the result set of MySQL using PHP?",
      "answer":"MySQLi methods\n1. mysqli_fetch_row\n2. mysqli_fetch_array\n3. mysqli_fetch_object\n4. mysqli_fetch_assoc\n\nPDO methods\n1. PDOStatement::fetch(PDO::FETCH_ASSOC)\n2. PDOStatement::fetch(PDO::FETCH_OBJ)\n3. PDOStatement::fetch()\n4. PDOStatement::fetch(PDO::FETCH_NUM)  "
    },

    {"id":"17",
      "q":"What is the use of explode() function ?",
      "answer":"Syntax : array explode ( string $delimiter , string $string [, int $limit ] );\nThis function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.  "
    },
    {"id":"18",
      "q":"What is the difference between explode() and str_split() functions? ",
      "answer":"str_split function splits string into array by regular expression. Explode splits a string into array by string. "
    },

    {"id":"19",
      "q":"What is the use of mysql_real_escape_string() function?",
      "answer":"It is used to escapes special characters in a string for use in an SQL statement   "
    },

    {"id":"20",
      "q":"How to strip whitespace (or other characters) from the beginning and end of a string ?",
      "answer":"The trim() function removes whitespaces or other predefined characters from both sides of a string. "
    },
    {"id":"21",
      "q":"What is the use of header() function in php ?",
      "answer":"The header() function sends a raw HTTP header to a client browser.\nRemember that this function must be called before sending the actual out put.\nFor example, You do not print any HTML element before using this function.   "
    },
    {"id":"22",
      "q":"How to redirect a page in php?",
      "answer":"The following code can be used for it, header(\"Location:index.php\"); "
    },

    {"id":"23",
      "q":"How stop the execution of a php script ?",
      "answer":"exit() function is used to stop the execution of a page"
    },{"id":"24",
      "q":"How to set a page as a home page in a php based site ?   ",
      "answer":"index.php is the default name of the home page in php based sites.."
    },{"id":"25",
      "q":"What is difference between require_once(), require(), include()?  ",
      "answer":"require() includes and evaluates a specific file, if the file is not found then it shows a Fatal Error.\nrequire_once() includes only the file which is not being included before. It is used to be recommended for the files where you have lots of functions stored.\ninclude() includes the file, even if the file is not found, but it gives a warning to the user to include()."
    },{"id":"26",
      "q":"What is the difference between echo, print and printf()?",
      "answer":"Echo is the basic type used to print out a string\nIt just shows the content of the message written using it.\nIt can have multiple parameters as well.\nprint is a construct,\nit returns TRUE on successful output and FALSE there is no output.\nIt can’t have multiple parameters.\n\nPrintf() is a function, and not be used as a construct.\nIt allows the string output to be formatted.\nIt is the slowest medium to print the data out."
    },{"id":"27",
      "q":"How PHP statement is different from PHP script?",
      "answer":"The difference between PHP statement and PHP script is that statements are set of instructions that tell PHP to perform an action. PHP script consists of a series of PHP statements that it uses for execution. PHP executes statements one at a time till it reaches the end of the script. Example is as follows:\nPHP statement: echo “Hi”;\n\nPHP script:\nif (time = midnight)\n{\nput on pajamas;\nbrush teeth;\ngo to bed;\n}"
    },{"id":"28",
      "q":"What are the method available in form submitting? ",
      "answer":" GET and POST"
    },{"id":"29",
      "q":"How can we register the variables into a session?",
      "answer":"<?php\nsession_register($ur_session_var);\n?>"
    },{"id":"30",
      "q":"How many ways we can pass the variable through the navigation between the pages? ",
      "answer":"Register the variable into the session\nPass the variable as a cookie\nPass the variable as part of the URL"
    },{"id":"31",
      "q":"How can we know the total number of elements of Array?",
      "answer":"sizeof($array_var)\ncount($array_var)"
    },{"id":"32",
      "q":"List out the predefined classes in PHP?",
      "answer":"Directory\n stdClass\n__PHP_Incomplete_Class\nexception\nphp_user_filter  "
    },{"id":"33",
      "q":"What type of inheritance that PHP supports?",
      "answer":"In PHP an extended class is always dependent on a single base class,that is, multiple inheritance is not supported.\nClasses are extended using the keyword 'extends'.   "
    },{"id":"34",
      "q":"What does a special set of tags <?= and ?> do in PHP?",
      "answer":"The output is displayed directly to the browser.  "
    },{"id":"35",
      "q":"How can I execute a php script using command line?",
      "answer":"Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument.\nFor example, \"php myScript.php\", assuming \"php\" is the command to invoke the CLI program.\nBe aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment."
    },{"id":"36",
      "q":"What is meant by nl2br()?",
      "answer":"Nl2br Inserts HTML line breaks before all newlines in a string string nl2br (string); For example: echo nl2br(\"god bless you\")will output \"god bless you\" to your browser.  "
    },{"id":"37",
      "q":"What are the three classes of errors that can occur in PHP?",
      "answer":"The three basic classes of errors are notices (non-critical), warnings (serious errors) and fatal errors (critical errors). "
    },{"id":"38",
      "q":"What is the difference between ereg_replace() and eregi_replace()?",
      "answer":"The function eregi_replace() is identical to the function ereg_replace() except that it ignores case distinction when matching alphabetic characters."
    },{"id":"39",
      "q":"What is the difference between the functions strstr() and stristr()? ",
      "answer":"The string function strstr(string allString, string occ) returns part of allString from the first occurrence of occ to the end of allString.\nThis function is case-sensitive.\nstristr() is identical to strstr() except that it is case insensitive."
    },{"id":"40",
      "q":"What’s a PHP Session? ",
      "answer":"PHP Session is an object created by the PHP engine that persists data between HTTP requests"
    },{"id":"41",
      "q":"What is Array in PHP ? ",
      "answer":"Array stores collection of values. You can declare array in PHP as like this.\n$fruits = array(‘apple’, ‘grape’, ‘orange’);"
    },{"id":"42",
      "q":"How to establish connection to MYSQL using PHP ?",
      "answer":"To establish connection we use MYSQL_CONNECT(HOSTNAME,USERNAME,PASSWORD) OR MYSQLI_CONNECT(HOSTNAME,USERNAME,PASSWORD,DATABASE)."
    },{"id":"43",
      "q":"How to Execute a Query in PHP against MYSQL ?",
      "answer":"To execute query PHP uses MYSQL_QUERY($QUERY) OR MYSQLI_QUERY($CONNECTION,$QUERY).."
    },{"id":"44",
      "q":"What is header() function in PHP ?",
      "answer":"It is used to send HTTP Header to the client browser. You need to use this function before passing actual output. You cannot print any HTML element before this function."
    },{"id":"45",
      "q":"How to define a constant in PHP ?",
      "answer":"To define a constant in PHP it uses “define” keyword.\nEx: define (“constant”,100)"
    },{"id":"46",
      "q":"How to send a mail in PHP ?",
      "answer":"You can send a mail in PHP with mail() function or SMTP details.  "
    },{"id":"47",
      "q":"What are arguments in Mail() in PHP ?",
      "answer":" It contains mail($to,$subject,$message,$headers)."
    },{"id":"48",
      "q":"How to get current session Id in PHP ?",
      "answer":"You can get current session id using session_id() function. "
    },{"id":"49",
      "q":"How to we stop SQL Injection in PHP? ",
      "answer":"You can prevent them by using mysqli_real_escape_string() or htmlentities() functions etc.  "
    },{"id":"50",
      "q":"How to can we encrypt data in PHP ? ",
      "answer":"MD5 PHP implements the MD5 hash algorithm using the md5 function,\neg : $encrypted_text = md5 ($msg);\n<p>mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] );\nEncrypts plaintext with given parameters."
},{"id":"51",
"q":"What are superglobal variables in PHP? ",
"answer":"There are $_GET,$_POST,$_SESSION,$_COOKIE,$_REQUEST etc. are called superglobal variables in PHP."
},
{"id":"52",
"q":"What is php.ini file?",
"answer":"It is simply a configuration file in PHP. It affects PHP functionality. You can use phpinfo() to check php.ini path. "
},{"id":"53",
"q":"What are MAGIC Constants in PHP ? ",
"answer":"PHP provides a large number of predefined constants to any script which it runs known as magic constants.  "
},{"id":"54",
"q":"54. What is the use of _LINE_ constant in PHP ?",
"answer":"It is to represent current line number of the file."
},{"id":"55",
"q":"What is Break statement in PHP ? ",
"answer":"It is to terminate code especially in for loop and switch etc."
},{"id":"56",
"q":"What is $_PHP_SELF in PHP ?",
"answer": " It is process the action same form."
},{"id":"57",
"q":"What is the use of $_FILE array in PHP ?  ",
"answer":"It is used represent file information of an uploading file."
},{"id":"58",
"q":"What is meant by PEAR in php? ",
"answer":"PEAR is the next revolution in PHP.\nThis repository is bringing higher level programming to PHP.\nPEAR is a framework and distribution system for reusable PHP components.\nIt eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library.\nPEAR also provides a command-line interface that can be used to automatically install \"packages\""
},{"id":"59",
"q":"What is the differences between $a != $b and $a !== $b? ",
"answer":"!= means inequality (TRUE if $a is not equal to $b) and !== means non-identity (TRUE if $a is not identical to $b)."
},{"id":"60",
"q":"How is it possible to cast types in PHP?  ",
"answer":"The name of the output type have to be specified in parentheses before the variable which is to be cast as follows:\n* (int), (integer) – cast to integer\n* (bool), (boolean) – cast to boolean\n* (float), (double), (real) – cast to float\n* (string) – cast to string\n* (array) – cast to array\n* (object) – cast to object "
},{"id":"61",
"q":"How to set a page as a home page in a php based site ? ",
"answer":"\nindex.php is the default name of the home page in php based sites"
},
{"id":"62",
"q":"How to redirect a page in php? ",
"answer":"The following code can be used for it, header(\"Location:index.php\");"
},
{"id":"63",
"q":"What is the use of header() function in php ? ",
"answer":"The header() function sends a raw HTTP header to a client browser.\nRemember that this function must be called before sending the actual out put.\nFor example, You do not print any HTML element before using this function."
},

{"id":"64",
"q":"How to strip whitespace (or other characters) from the beginning and end of a string ?",
"answer":"\nThe trim() function removes whitespaces or other predefined characters from both sides of a string."
},

{"id":"65",
"q":"What is the use of explode() function ?",
"answer":"Syntax : array explode ( string $delimiter , string $string [, int $limit ] );\nThis function breaks a string into an array.\nEach of the array elements is a substring of string\nformed by splitting it on boundaries formed by the string delimiter."
},
{"id":"66",
"q":"what is the use of isset() in php?",

"answer":"This function is used to determine if a variable is set and is not NULL"
},

{"id":"67",
"q":"Distinguish between urlencode and urldecode?",
"answer":"This method is best when encode a string to used in a query part of a url.\nit returns a string in which all non-alphanumeric characters except -_.\nhave replece with a percentege(%) sign .\nthe urldecode->Decodes url to encode string as any %and other symbole are decode by the use of the urldecode() function."
},

{"id":"68",
"q":"How is it possible to set an infinite execution time for PHP script?",

"answer":"The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded’.It is also possible to specify this in the php.ini file."
},

{"id":"69",
"q":"What does the unset() function means?",
"answer":"The unset() function is dedicated for variable management. It will make a variable undefined."
},
{"id":"70",
"q":"How can we automatically escape incoming data?",
"answer":"We have to enable the Magic quotes entry in the configuration file of PHP."
},

{"id":"71",
"q":"How can we access the data sent through the URL with the POST method?",
"answer":"To access the data sent this way, you use the $_POST array.Imagine you have a form field called ‘var’ on the form, when the user clicks submit to the post form, you can then access the value like this:\n$_POST[“var”];"
},

{"id":"72",
"q":"How the result set of Mysql be handled in PHP?",
"answer":"The result set can be handled using mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object or mysql_fetch_row."
},

{"id":"73",
"q":"How a constant is defined in a PHP script?",
"answer":"The define() directive lets us defining a constant as follows:\ndefine (“ACONSTANT”, 123);"},

{"id":"74",
"q":"If the variable $var1 is set to 10 and the $var2 is set to the character var1, what’s the value of $$var2?",
"answer":"$$var2 contains the value 10."
},
{"id":"75",
"q":"In PHP, objects are they passed by value or by reference?",
  "answer":"In PHP, objects passed by value."
},

{"id":"76",
"q":"What is faster? ",
"answer":" 1- Combining two variables as follows:\n$variable1 = ‘Hello ‘;\n$variable2 = ‘World’;\n$variable3 = $variable1.$variable2;\n\nOr\n2- $variable3 = “$variable1$variable2”;\n$variable3 will contain “Hello World”. The first code is faster than the second code especially for large large sets of data."
},
{"id":"77",
"q":"What’s the difference between __sleep and __wakeup?",
"answer":"sleep returns the array of all the variables that need to be saved, while __wakeup retrieves them."
},
{"id":"78",
"q":"What does $GLOBALS means?",
"answer":"$GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script."
},
{"id":"79",
"q":"What is the use of $_Server and $_Env?",
"answer":"$_SERVER and $_ENV arrays contain different information. The information depends on the server and operating system being used. Most of the information can be seen of an array for a particular server and operating system. The syntax is as follows\nforeach($_SERVER as $key =>$value)\n{\necho “Key=$key, Value=$value\n”;\n}"
},
{"id":"80",
"q":"How to create reusable code in PHP?",
"answer":"Applications created in PHP often perform the same task in same script or in different scripts.\nTo create a reusable code functions are used.\nFunctions are group of PHP statements that perform a specific task."
},{"id":"81",
"q":"What does ODBC do in context with PHP? ",
"answer":"PHP supports many databases like dBase, Microsft SQL Server, Oracle, etc. But, it also supports databases like filePro, FrontBase and InterBase with ODBC connectivity. ODBC stands for Open Database connectivity, which is a standard that allows user to communicate with other databases like Access and IBM DB2."
},{"id":"82",
"q":"What is the difference between PHP and JavaScript?",
"answer":"The difference lies with the execution of the languages. PHP is server side scripting language, which means that it can’t interact directly with the user. Whereas, JavaScript is client side scripting language, that is used to interact directly with the user."
},{"id":"83",
"q":"Write a Hello world program using variable?",
"answer":"To write the hello world program in PHP using variable you need to know the tags that are used in HTML and the PHP coding which is as follows:\n<html>\n<head><title>Hello World Script using Variable</title></head>\n<body>\n<?php\n$salutation = “Hello World!”;\necho “<p>$salutation</p>”;\n?>\n</body>\n</html>"
},{"id":"84",
"q":"How can we know the count/number of elements of an array?",
"answer":"2 ways-\n(a) sizeof($urarray) This function is an alias of count()\n(b) count($urarray)"
},{"id":"85",
"q":"How can I know that a variable is a number or not using a JavaScript?",
"answer":"bool is_numeric ( mixed var) Returns TRUE if var is a number or a numeric string, FALSE otherwise.or use isNaN(mixed var)The isNaN() function is used to check if a value is not a number."
},{"id":"86",
"q":"What does type casting mean in PHP? Explain with an example?",
"answer":"PHP automatically store the data and interprets according to itself. Type casting is a way to assign the variable according to your need and requirement and not allowing PHP to assign it automatically. To specify the type, it can be used like:\n$newint = (int) $var1;\n$newfloat = (float) $var1;\n$newstring = (string) $var1;\nThe value in the variable on the right side of the equal sign is stored in the variable on the left side as the specified type.\n"
},
{"id":"87",
"q":"How the result set of Mysql be handled in PHP?",
"answer":"The result set can be handled using mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object or mysql_fetch_row."
},
{"id":"88",
"q":"Which function gives us the number of affected entries by a query?",
"answer":"mysql_affected_rows() return the number of entries affected by an SQL query."
},
{"id":"89",
"q":"What are the encryption techniques in PHP",
"answer":"MD5 PHP implements the MD5 hash algorithm using the md5 function,\n<?php\n$encrypted_text = md5 ($msg);\n?>\n"
},
{"id":"90",
"q":"What is x+ mode in fopen() used for?",
"answer":"Read/Write. Creates a new file. Returns FALSE and an error if file already exists  "
},
{"id":"91",
"q":"what is the use of isset() in php?",
"answer":"This function is used to determine if a variable is set and is not NULL"
},

{"id":"92",
"q":"what is the use of rand() in php?  ",
"answer":"It is used to generate random numbers.\nIf called without the arguments it returns a pseudo-random integer between 0 and getrandmax().\nIf you want a random number between 6 and 12 (inclusive), for example, use rand(6, 12).\nThis function does not generate cryptographically safe values, and should not be used for cryptographic uses.\nIf you want a cryptographically secure value, consider using openssl_random_pseudo_bytes() instead."
},

{"id":"93",
"q":"What is the use of header() function in php ?\n",
"answer":"The header() function sends a raw HTTP header to a client browser.Remember that this function must be called before sending the actual out put.For example, You do not print any HTML element before using this function."
},
{"id":"94",
"q":"What does $_FILES means?",
"answer":"$_FILES is an associative array composed of items sent to the current script via the HTTP POST method.  "
},
{"id":"95",
"q":"What is the difference between $_FILES[‘userfile’][‘name’] and $_FILES[‘userfile’][‘tmp_name’]?",
"answer":"$_FILES[‘userfile’][‘name’] represents the original name of the file on the client machine,\n$_FILES[‘userfile’][‘tmp_name’] represents the temporary filename of the file stored on the server."
},
{"id":"96",
"q":"When we will go for forms authentication?",
"answer":"Forms authentication is used for normal web applications."
},{"id":"97",
"q":"When we will go for passport authentication?  ",
"answer":"A group of websites which will allow the user with single user id and password will go for the passport authentication.  Ex: If we have Gmail id with that we can access Gmail, Facebook, Youtube etc"
},{"id":"98",
"q":"What does $_ENV means?",
"answer":"$_ENV is an associative array of variables sent to the current PHP script via the environment method."
},{"id":"99",
"q":"What does $_COOKIE means?",
"answer":"$_COOKIE is an associative array of variables sent to the current PHP script using the HTTP Cookies."
},

{"id":"100",
"q":"what the difference between the ‘BITWISE AND’ operator and the ‘LOGICAL AND’ operator?",
"answer":"$a and $b:TRUE if both $a and $b are TRUE.\n$a & $b:Bits that are set in both $a and $b are set.   "
}







]

}