sivasoft interview questions

sivasoft interview questions

Php Interview Questions

1.What is Full form of PHP ?

A.PHP: Hypertext Preprocessor.

2.Who is the father or inventor of PHP ?

A.Rasmus Lerdorf is known as the father of PHP that started development of PHP in 1994 for their own Personal Home Page (PHP) and they released PHP/FI (Forms Interpreter) version 1.0 .

3.How can we submit from without a submit button?

A.We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form.

4.How many ways we can retrieve the date in result set of mysql Using php?

A.As individual objects so single record or as a set or arrays.

5.How can I execute a php script using command line?

A.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. Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

6.What are the current versions of apache, php, and mysql?

A.PHP: php 5.3 , MySQL: MySQL 5.5, and Apache: Apache 2.2

7.How can we encrypt the username and password using php?

A.You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password"); We can encode data using base64_encode($string) and can decode using base64_decode($string);

8.What is the difference between the functions unlink and unset?

A.Unlink() deletes the given file from the file system. unset() makes a variable undefined.

9.What is meant by urlencode and urldocode?

A.Urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25?. URL encoded strings are safe to be used as part of URLs. urldecode() returns the URL decoded version of the given string.

10.How can we register the variables into a session?

A.We can use the session_register ($ur_session_var) function.

11.What is the maximum size of a file that can be uploaded using php and how can we change this?

A.You can change maximum size of a file set upload_max_filesize variable in php.ini file.

12.How can we increase the execution time of a php script?

A.Set max_execution_time variable in php.ini file to your desired time in second.

13.Set max_execution_time variable in php.ini file to your desired time in second.

A.session_id() function returns the session id for the current session.

14.How can we destroy the session, how can we unset the variable of a session?

A.session_destroy and session_unset.

15.How can we destroy the cookie?

A.Set same the cookie in past

16.What is the difference between ereg_replace() and eregi_replace()?

A.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.

17.How can we know the count/number of elements of an array?

A.There are two ways, They are : sizeof($urarray) This function is an alias of count() and count($urarray) .

18.What is the maximum length of a table name, database name, and fieldname in mysql?

A.Database name- 64 Table name -64 Fieldname-64

19.What is meant by PEAR in php?

A.PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit.It is a structured library of open-sourced code for PHP users . A system for code distribution and package maintenance

20.What is PHP?

A.PHP Version 3.0 is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

21.Is PHP a case sensitive programming language?

A.PHP is a partially case sensitive programming language. We can use function names, class names in case insensitive manner.

22.What is mean by LAMP?

A.LAMP means combination of Linux, Apache, MySQL and PHP.

23.How to find the number of elements in an array?

A.Using count($array) or sizeof($array).

24.How do you make one way encryption for your passwords in PHP?

A.Using md5 function or sha1 function

25.What is the difference between echo and print statement?

A.echo() can take multiple expressions, print cannot take multiple expressions. Print return true or false based on success or failure whereas echo just does what its told without letting you know whether or not it worked properly.

26.What Is a Session?

A.A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests. There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor. Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor. Session stored in server.

27.Explain about PHP looping?

A.Looping statements are used in PHP to execute the code for a developer defined number of times. PHP has these following looping statements they are while, do while, for and for each. Foreach is used to loop a block of code in each element in an array.

28.What is triggers ?

A.A trigger is a database object which is associated with particular database table. Triggers gets called automatically when particular event(INSERT, UPDATE, DELETE) occurs on table. In MySQL, Triggers gets supported after MySQL 5.0.2

29.What are the different types of errors in PHP ?

A.Fatal, Warning and Notices.

30.How to include a file to a php page?

A.We can include a file using "include() " or "require()" function with file path as its parameter.

31.Differences between GET and POST methods ?

A.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 .

32.What is use of in_array() function in php ?

A.in_array used to checks if a value exists in an array

33.What is use of count() function in php ?

A.count() is used to count all elements in an array, or something in an object.

34.What is the difference between Session and Cookie?

A.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. Cookies can not hold multiple variables,But Session can hold multiple variables.We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking.

35.How to set cookies in PHP?

A.Setcookie("sample", "ram", time()+3600);

36.How to Retrieve a Cookie Value?

A.echo $_COOKIE["user"];

37.what types of loops exist in php?

A.for,while,do while and foreach (NB: You should learn its usage).

38.How to create a mysql connection?

A.mysql_connect(servername,username,password);

39.How to select a database?

A.mysql_select_db($db_name);

40.What is the use of explode() function ?

A.Syntax : array explode ( string $delimiter , string $string [, int $limit ] ); This 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.

41.What is the difference between explode() and split() functions?

A.Split function splits string into array by regular expression. Explode splits a string into array by string.

42.How to strip whitespace (or other characters) from the beginning and end of a string ?

A.The trim() function removes whitespaces or other predefined characters from both sides of a string.

43.What is the use of header() function in php ?

A.The header() function sends a raw HTTP header to a client browser.

44.How to redirect a page in php?

A.The following code can be used for it, header("Location:index.php");

45.How stop the execution of a php script ?

A.exit() function is used to stop the execution of a page.

46.How to set a page as a home page in a php based site ?

A.index.php is the default name of the home page in php based sites.

47.How to find the length of a string?

A.strlen() function used to find the length of a string.

48.what is the use of rand() in php?

A.It is used to generate random numbers.

49.How do you define a constant?

A.Using define() directive, like define ("MYCONSTANT",150).

50.What is the use of "ksort" in php?

A.It is used for sort an array by key in reverse order.

51.What is the use of the function htmlentities?

A.htmlentities Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

52.what is sql injection ?

A.SQL injection is a malicious code injection technique.It exploiting SQL vulnerabilities in Web applications

53.What is x+ mode in fopen() used for?

A.Read/Write. Creates a new file. Returns FALSE and an error if file already exists

54.How to find the position of the first occurrence of a substring in a string?

A.strpos() is used to find the position of the first occurrence of a substring in a string.

55.What is the difference between mysql_fetch_object and mysql_fetch_array?

A.mysql_fetch_object() is similar tomysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).

56.Can we use include (�abc.PHP�) two times in a PHP page �makeit.PHP�?

A.Yes we can use include() more than one time in any page though it is not a very good practice.

57.Functions in IMAP, POP3 AND LDAP?

A.You can find these specific information in PHP Manual.

58.What is the use of friend function?

A.Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.

59.What is meant by notice errors in php?

A.Notices: These are trivial, non-critical errors that PHP encounters while executing a script � for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all � although, as you will see, you can change this default behavior.

60.What is meant by warning errors in php?

A.These are more serious errors � for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.

61.What is meant by fatal errors in php?

A.Fatal errors: These are critical errors � for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP�s default behavior is to display them to the user when they take place.

62.How can we get second of the current time using date function?

A.$second = date(�s�);

63.What is the PHP predefined variable that tells the What types of images that PHP supports?

A. Though i am not sure if this is wrong or not, With the exif extension you are able to work with image meta data.

64.How can I make a script that can be bi-language (supports English, German)?

A.You can maintain two separate language file for each of the language. all the labels are putted in both language files as variables and assign those variables in the PHP source. on runtime choose the required language option.

65.What are the difference between abstract class and interface?

A.Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

66.What type of inheritance that PHP supports?

A.In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword "extends".

67.What are the advantages/disadvantages of MySQL and PHP?

A.Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and JSP.

68.What is the functionality of md5 function in PHP?

A.Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. I use it to generate keys which I use to identify users etc. If I add random no techniques to it the md5 generated now will be totally different for the same string I am using.

69.What is the functionality of md5 function in PHP?

A.Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. I use it to generate keys which I use to identify users etc. If I add random no techniques to it the md5 generated now will be totally different for the same string I am using.

70.What does a special set of tags <?= and ?> do in PHP?

A.The output is displayed directly to the browser.

71.How can I execute a PHP script using command line?

A.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. Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

72.How do you pass a variable by value?

A.Just like in C++, put an ampersand in front of it, like $a = &$b

73.What is the functionality of the functions STRSTR() and STRISTR()?

A.string strstr ( string haystack, string needle ) returns part of haystack string from the first occurrence of needle to the end of haystack. This function is case-sensitive. stristr() is idential to strstr() except that it is case insensitive.

74.When are you supposed to use endif to end the conditional statement?

A.When the original if was followed by : and then the code block without braces.

75.How do I find out the number of parameters passed into function9?

A.func_num_args() function returns the number of parameters passed in.

76.If the variable $a is equal to 5 and variable $b is equal to character a, what�s the value of $$b?

A.100, it�s a reference to existing variable.

77.Would you initialize your strings with single quotes or double quotes?

A.Since the data inside the single-quoted string is not parsed for variable substitution, it�s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

78.How come the code works, but doesnt for two-dimensional array of mine?

A.Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would have worked.

79.With a heredoc syntax, do I get variable substitution inside the heredoc contents?

A.Yes.

80.What is the difference between characters 23 and x23?

A.The first one is octal 23, the second is hex 23.

81.What are the different functions in sorting an array?

A.Sorting functions in PHP:asort(), arsort(), ksort(), krsort(), uksort(), sort(), natsort() and rsort().

82.Whats the difference between md5(), crc32() and sha1() crypto on PHP?

A.The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

83.Will comparison of string "10" and integer 11 work in PHP?

A.Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.

84.What is the functionality of MD5 function in PHP?

A.string md5(string). It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.

85.What is the difference between PHP4 and PHP5?

A.PHP4 cannot support oops concepts and Zend engine 1 is used. PHP5 supports oops concepts and Zend engine 2 is used. Error supporting is increased in PHP5. XML and SQLLite will is increased in PHP5.

86.What are encryption functions in PHP?

A.CRYPT() and MD5()

87.What types of images that PHP supports ?

A.Using imagetypes() function to find out what types of images are supported in your PHP engine. imagetypes() - Returns the image types supported. This function returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.

88.How can we destroy the cookie?

A.Set the cookie with a past expiration time.

89.What are the functions for IMAP?

A. IMAP is used for communicate with mail servers.Imap_alerts � Returns all the imap errors occurred,Imap_body � Reads the message body,Imap_check � Reads the current mail box,Imap_clearflag_full � Clears all flags.

90.What is Type juggle in php?

A.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.

91.What is Joomla in PHP?

A.Joomla is an open source content management system. Joomla can be used in PHP as a framework to publish web contents. Joomla allows the user to manage the content of the web pages with ease.

92.What is zend engine?

A.Zend Engine is used internally by PHP as a complier 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.

93.What is the difference between Split and Explode?

A.Both the functions are used to Split a string. However, Split is used to split a string using a regular expression. On the other hand, Explode is used to split a string using another string.

94.What is CAPTCHA?

A.CAPTCHA is a test to determine if the user using the system (usually a web form) is a human. It identifies this by throwing challenges to users. Depending on the responses the identification can be made. E,g Answering to identification of distorted images. Captcha Creator is a PHP Script that generates Strong Captchas.

95.What is difference between developing website using Java and PHP?

A.In order to make interactive pages, java uses JSP (Java Server pages). PHP is open source while JSP is not. Libraries are much stronger in Java as compared tp PHP. Huge codes can be managed with ease in Java by making classes.

96.How can I embed a java programme in php file?

A.PHP can be integrated into the servlet environment of java or java support can be integrated with php.the java extension can be used to create and invoke methods on Java objects from PHP.

97.How do you create sub domains using PHP?

A.Wild card domains can be used. Sub domains can be created by first creating a sub directory in the /htdocs folder. E.g. /htdocs/mydomain. Then, the host file needs to be modified to define the sub domain. If the sub domains are not configured explicitly, all requests should be thrown to the main domain.

98.What is the difference between Notify URL and Return URL?

A.Notify URL and Return URL is used in Paypal Payment Gateway integration. Notify URL is used by PayPal to post information about the transaction. Return URL is sued by the browser; A url where the user needs to be redirected on completion of the payment process.

99.Why PHP is also called as Scripting language?

A.PHP is basically a general purpose language, which is used to write scripts. Scripts are normal computer files that consist of instructions written in PHP language. It tells the computer to execute the file and print the output on the screen. PHP is used for webpages and to create websites, thus included as scripting language.

100.Why many companies are switching their current business language to PHP? Where PHP basically used?

A.PHP is rapidly gaining the popularity and many companies are switching their current language for this language. PHP is a server side scripting language. PHP executes the instructions on the server itself. Server is a computer where the web site is located. PHP is used to create dynamic pages and provides faster execution of the instructions.

101.What is the use of PEAR in php?

A.PEAR is known as PHP Extension and Application Repository. It provides structured library to the PHP users and also gives provision for package maintenance.

102.PHP being an open source is there any support available to it?

A.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.

103.Why PHP is sometimes called as embedded scripting language?

A.PHP is a high level language which is used to allow users to write and understand it in human readable form and also use an interpreter to interpret the code which user write for the computer. PHP is used as an embedded scripting language for the web. PHP is embedded in HTML code. HTML tags are used to enclose the PHP language. HTML is used and PHP is code written in it in the same way as you write JavaScript in HTML.

104.What is difference between require_once(), require(), include()?

A.require() includes and evaluates a specific file, if the file is not found then it shows a Fatal Error. require_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. include() includes the file, even if the file is not found, but it gives a warning to the user to include().

105.How the web server interprets PHP and interacts with the client?

A.After installing and configuring the PHP, the web When PHP is installed, the Web server looks for PHP code that is embedded in HTML file with its extension. The extensions which are used are .php or .phtml. When web server receives a request for the file with an appropriate extension, HTML statements are processed and PHP statements are executed on the server itself. When the processing gets over the output is being shown in HTML statements.

106.What is the difference between echo, print and printf()?

A.Echo is the basic type used to print out a string. It just shows the content of the message written using it. It can have multiple parameters as well. print is a construct, it returns TRUE on successful output and FALSE there is no output. It can�t have multiple parameters. Printf() is a function, and not be used as a construct. It allows the string output to be formatted. It is the slowest medium to print the data out.

107.How PHP statement is different from PHP script?

A.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.

108.What are the different types of statements that are present in PHP?

A.Simple statement, Complex/Conditional statements and Looping statements.

109.What are the method available in form submitting?

A.GET and POST.

110.How many open modes available when a file open in PHP?

A.r , r+ , w , w+ , a , a+ , x , x+

111.Explain mysql_error()?

A.The mysql_error() message will tell us what was wrong with our query, similar to the message we would receive at the MySQL console.

112.Explain mysql_errno()?

A.Returns the numerical value of the error message from previous MySQL operation.

113.What is Constructor?

A.CONSTRUCTOR : PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.

114.What is Destructor?

A.DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.

115.What is Destructor?

A.DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.