besanttechnologies Flashcards
Interview
What is PHP?
PHP is a server side scripting language. It requires a web server to perform execution like Apache, IIS etc. It helps to create a dynamic web applications. PHP is a market leader in-terms of usage. It holds more than 82% of total web market share as of 2015.
Who is the father of PHP?
Rasmus Lerdorf. He created PHP in the year of 1994.
Acronym of PHP?
Now PHP stands for “PHP : Hypertext Preprocessor“. Before PHP 4 it was called as “Personal Home Page Tools”.
Explain the difference between static and dynamic websites?
Static Websites : A webpage or website which was developed by using HTML alone.
Dynamic Websites : A webpage or website which was developed by using any dynamic languages like PHP, ASP.NET, JSP etc
What is the name of scripting engine in PHP?
ZEND Engine 2 is the name of the scripting engine that powers PHP.
What are the methods of form submitting in PHP?
We can use GET (or) POST for form submission in PHP.
What is a session?
A session is a logical object enabling us to preserve temporary data across multiple PHP pages. A PHP session is no different from a normal session. It can be used to store information on the server for future use. However this storage is temporary and is flushed out when the site is closed.
What is the method to register a variable into a session?
< ?php session_register($name_your_session_here); ?>
What are the encryption functions in PHP?
md5() – Calculate the md5 hash of a string
sha1() – Calculate the sha1 hash of a string
hash() – Generate a hash value
crypt() – One-way string hashing
What are the different types of errors in PHP?
There are 3 types of errors in PHP.
Notices : These are the non-critical errors. These errors are not displayed to the users.
Warnings : These are more serious errors but they do not result in script termination. By default, these errors are displayed to the user.
Fatal Errors : These are the most critical errors. These errors may be a cause of immediate termination of script.
What is the difference between $besant and $$besant?
$besant stores variable data while $$besant is used to store variable of variables.
$besant stores fixed data whereas the data stored in $$besant may be changed dynamically.
How do you connect MySQL database with PHP?
There are two methods to connect MySQL database with PHP. Procedural and Object Oriented style.
Difference echo() and print()?
Echo can output one or more string but print can only output one string and always returns 1.
Echo is faster than print because it does not return any value.
Differentiate between require and include?
Require and include both are used to include a file, but if file is not found include sends warning whereas require sends Fatal error.
What is the use of count() function in PHP?
count() function is used to count total elements in the array, or something an object.
What is the difference between session and cookie?
The main difference between session and cookies is that cookies are stored on the user’s computer while sessions are stored on the server side.
Cookies can’t hold multiple variables on the other hand Session can hold multiple variables.
You can manually set an expiry for a cookie, while session only remains active as long as browser is open.
How can you retrieve a cookie value?
echo $_COOKIE [“cookie_name”];
What is the use of header() function in PHP?
The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can’t print any HTML element before using this header function.
What is the array in PHP?
Array is used to store multiple values in single name. In PHP, it orders in keys and values pairs. It is not a datatype dependent in PHP.
How can you submit a form without a submit button?
Possible only by using JavaScript. You can use JavaScript submit() function to submit the form without explicitly clicking any submit button.
Explain the importance of the function htmlentities
The htmlentities() function converts characters to HTML entities.
What is MIME?
MIME – Multi-purpose Internet Mail Extensions.
MIME types represents a standard way of classifying file types over Internet.
Web servers and browsers have a list of MIME types, which facilitates files transfer of the same type in the same way, irrespective of operating system they are working in.
A MIME type has two parts: a type and a subtype. They are separated by a slash (/).
MIME type for Microsoft Word files is application and the subtype is msword, i.e. application/msword.
How can we increase the execution time of a php script?
By default the PHP script takes 30secs to execute. This time is set in the php.ini file. This time can be increased by modifying the max_execution_time in seconds. 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.
What is Type juggle in php?
Type Juggling means dealing with a variable type. In PHP a variables type is determined by the context in which it is used. If an integer value is assigned to a variable, it becomes an integer.
E.g. $var3= $var1 + $var2
Here, if $var1 is an integer. $var2 and $var3 will also be treated as integers.
What is the difference between mysql_fetch_object() and mysql_fetch_array()?
mysql_fetch_object() returns the result from the database as objects while mysql_fetch_array() returns result as an array. This will allow access to the data by the field names. E.g. using mysql_fetch_object() field can be accessed as $result->fieldname and using mysql_fetch_array() field can be accessed as $result->[‘fieldname’]
What is the difference between the functions unlink and unset?
The function unlink() is to remove a file, where as unset() is used for destroying a variable that was declared earlier.
unset() empties a variable or contents of file.
What is Joomla in PHP?
Joomla is an open source content management system. Joomla allows the user to manage the content of the web pages with ease.
What is the difference between preg_split() and explode()?
preg_split — Split string by a regular expression
< ?php // split the phrase by any number of commas or space characters, // which include “ “, \r, \t, \n and \f $keywords = preg_split(“/[\s,]+/”, “hypertext language, programming”); print_r($keywords); ?>
explode — Split a string by string
< ?php // Example 1 $pizza = “piece1 piece2 piece3 piece4 piece5 piece6”; $pieces = explode(“ “, $pizza); echo $pieces[0]; // piece1 echo $pieces[1]; // piece2 ?>
How to upload files using PHP?
– Select a file from the form using
– Specify the path into which the file is to be stored.
– Insert the following code in php script to upload the file.
move_uploaded_file($_FILES[“file”][“tmp_name”], “myfolder/” . $_FILES[“file”][“name”]);
Describe functions strstr() and stristr()?
Both the functions are used to find the first occurrence of a string. Parameters includes: input String, string whose occurrence needs to be found, TRUE or FALSE (If TRUE, the functions return the string before the first occurrence.)
stristr() is similar to strstr(). However, it is case-insensitive.
Explain the purpose of output buffering in PHP
Without output buffering (the default), your HTML is sent to the browser in pieces as PHP processes through your script. With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script.
Advantages of output buffering for Web developers
– Turning on output buffering alone decreases the amount of time it takes to download and render our HTML because it’s not being sent to the browser in pieces as PHP processes the HTML.
– All the fancy stuff we can do with PHP strings, we can now do with our whole HTML page as one variable.
– If you’ve ever encountered the message “Warning: Cannot modify header information – headers already sent by (output)” while setting cookies, you’ll be happy to know that output buffering is your answer.
How can we know the number of days between two given dates using PHP?
Object oriented style:
$datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-13'); $interval = $datetime1->diff($datetime2); echo $interval->format('%R%a days'); Procedural style:
$datetime1 = date_create(‘2009-10-11’);
$datetime2 = date_create(‘2009-10-13’);
$interval = date_diff($datetime1, $datetime2);
echo $interval->format(‘%R%a days’);
What is the difference between PHP and JavaScript?
While JS is used for client side scripting (except in node.js) and PHP is used for server side scripting.
Simply, JavaScript codes are executed by your web browser, like the catchy animations or simple calculations . Your browser does all the processing. While PHP runs on the server, where your webpage is stored. The server computer does all PHP processing and it sends the result to your browser.
What does ODBC do in context with PHP?
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.
What is difference between require_once(), require(), include()?
Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don’t include the file more times and you will not get the “function re-declared” error.
Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING.
There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().
PHP being an open source is there any support available to it?
PHP is an open source language, and it is been said that it has very less support online and offline. But, PHP is all together a different language that is being developed by group of programmers, who writes the code. There is lots of available support for PHP, which mostly comes from developers and PHP users.
How php concatenation works?
Two strings can be joined together by the use of a process called as concatenation. A dot (.) operator is used for this purpose. Example is as follows: $string1 = "Hello"; $string2 = " World!"; $stringall = $string1.$string2; echo $stringall;
What is the use of super-global arrays in PHP?
Super global arrays are the built in arrays that can be used anywhere. They are also called as auto-global as they can be used inside a function as well. The arrays with the longs names such as $HTTP_SERVER_VARS, must be made global before they can be used in an array. This $HTTP_SERVER_VARS check your php.ini setting for long arrays.
What is the use of $_SERVER and $_ENV?
$_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:
foreach($_SERVER as $key =>$value)
{ echo “Key=$key, Value=$value\n”; }
Write a statement to show the joining of multiple comparisons in PHP?
PHP allows multiple comparisons to be grouped together to determine the condition of the statement. It can be done by using the following syntax:
comparison1 and|or|xor comparison2 and|or|xor comparison3 and|or|xor.
The operators that are used with comparisons are as follows:
1. and: result in positive when both comparisons are true.
2. or: result in positive when one of the comparisons or both of the comparisons are true.
3. xor: result in positive when one of the comparisons is true but not both of the comparisons.
Example:
$resCity == “Reno” or $resState == “NV” and $name == “Sally”