Download pdf of php interview questions and answers




















To avoid this, and get a properly formatted string, it's worth using ie. Question - I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters.

How do I accomplish that with PHP? For printing out strings, there are echo, print and printf. Explain the differences. It is also generally argued that echo is faster, but usually the speed ns. Question - Can we use include "abc.

Ans: Yes. How many ways we can retrieve the date in result set of mysql using php? Ans: As individual objects so single record or as a set or arrays. View All Answers O. Question - How can we create a database using PHP and mysql? Question - How can we submit form without a submit button? Ans: 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. Question - With a heredoc syntax, do I get variable substitution inside the heredoc contents? Question - How come the code works, but does not for two-dimensional array of mine?

Any time you have an array with more than one dimension, complex parsing syntax is required. Question - What is the difference between the functions unlink and unset? Ans: unlink is a function for file system handling. It will simply delete the file in context. It will make a variable undefined. How can we extract string abc. For example: A. Question - w.

Would you initialize your strings with single quotes or double quotes? Ans: er. 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.

Question - How can we submit a form without a submit button? Ans: If you don't want to use the Submit button to submit a form, you can use normal hyper links to submit a form. Ans: Here are three basic types of runtime errors in PHP: 1. 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 you can change this default behavior.

Warnings: These are more serious errors - for example, attempting to include a file which does not exist. 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. Internally, these variations are represented by twelve different error types In.

Post method doesn't display these values. Ans: st. Question - Are objects passed by value or by reference? Ans: Everything is passed by value. Ans: If you want to include special characters like spaces in the query string, you need to protect them by applying the urlencode translation function. The script below shows how to use urlencode : w. Ans: , it's a reference to existing variable.

Question - What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain? The files have names that begin with the table name and have an extension to indicate the file type. The '. The data file has a '. The index file has a '. Question - How do I find out the number of parameters passed into function9.

Question - What is the functionality of the function strstr and stristr? Ans: strstr returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr "user example.

Question - How can we send mail using JavaScript? Ans: No. There is no way to send emails directly using JavaScript. But you can use JavaScript to execute a client side email program send the email using the "mailto" code.

Question - When are you supposed to use endif to end the conditional statement? Ans: When the original if was followed by : and then the code block without braces. Question - O. Ans: R. This function is case-sensitive. Question - How do you pass a variable by value? Question - How can we encrypt the username and password using PHP?

For example,. View All Answers st. Which type of table is generated when we are creating a table in the following syntax: create table employee eno io. Total 5 types of tables we can create 1. MyISAM 2. Heap 3. Merge 4. ISAM A. Question - I am trying to assign a variable the value of , but it keeps coming up with a different number, what is the problem?

Ans: PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems. For example, "php myScript.

Ans: Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them.

Anwser 1: urlencode returns the URL encoded version of the given string. For example: urlencode " Anwser 2: string urlencode str - Returns the URL encoded version of the input string. In the URL encoded version: ue. Alphanumeric characters are maintained as is. If the specified file is included previous to the present ns. But require and include will do it as many times they are asked to do. This is a behavior similar to the include statement, with the only difference being that if the code from a file has already been included, it will not be included again.

The major difference between include and require is that w. Anwser 3: All three are used to an include file into the current page. If the file is not present, require , calls a fatal error, while in include does not.

It des not call a fatal error if file not exists. Anwser 4: File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored. How do you define a constant in PHP? The output is displayed directly to the browser. Ans: A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer.

By default, cookies are created as temporary cookies which Q. When the browser is closed, temporary cookies will be erased. Ans: Anwser 1: ns. Anwser 2: They are both variables. How can we repair a MySQL table? Question - How can we know the number of days between two given dates using PHP? This repository is bringing higher level programming to PHP. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library.

The project has been founded by Stig S. Bakken in and quite a lot of people te. 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 w. Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

What is PHP? Ans: The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. This script will print: Warning: System will shutdown in 15 minutes! Warning: System will shutdown in 5 minutes! Ans: If you know the position of a substring in a given string, you can take the substring out by the substr function.

Here is a PHP script on how to use substr : R. Ans: Because strpos could two types of values, Integer and Boolean, you need to be careful about testing the return value. Ans: To find a substring in a given string, you can use the strpos function. Othewise, it will return a Boolean false.

Here is a PHP script example of trimming strings: Q. Ans: You can use the "strlen " function to get the number of characters in a string. Ans: In a numeric context, PHP will automatically convert any string to a numeric value.

Strings will be converted into two types of numeric values, double floating number and integer, based on the following rules: R. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 zero.

Otherwise, it will be converted to an integer. Ans: In a string context, PHP will automatically convert any numeric value to a string. The concatenation operator. Expression 1. The result is "3 " because concatenation operations and addition operation are carried out from left to right. Those operators use ASCII values of characters from both strings to determine the comparison results.

Question - R. Ans: You can use the string concatenation operator. This allows you to assign a new character to any position in a string. In this format, you can not specify the element key in quotes. In this format, the array element expression is specified in the same way as in a normal statement. A banana is yellow. Ans: There are 3 formats to include variables in double-quoted strings: R.

The variable name starts with the dollar sign and ends at the first character that can not be used in variable name. Space is good character to end a variable name. You use this format to specify any complex variable expression in the same way as in a normal statement. He drank some Heinekens and water. She drank some Heinekens and water. Variables included in double-quoted strings will be interpolated. Their values will be concatenated into the enclosing strings.

Ans: There are 12 escape sequences you can use in double-quoted strings: ue. Ans: There are two special characters you need to escape in a double-quote string: the double quote " and the back slash.

Here is a PHP script example of w. Hello world! Tom said: "Who's there? Ans: G. You can not specify the "new line" character in a single-quoted string. Ans: There are two special characters you need to escape in a single-quote string: the single quote ' and the back slash. How do you call a constructor for a parent class? Would you initialize your strings with single quotes or double quotes in PHP? Answer: 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.

I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP? What"s the output of the ucwords function in the example below? To avoid this, and get a properly formatted string, it"s worth using strtolower first. What"s the difference between htmlentities and htmlspecialchars?

What"s the difference between md5 , crc32 and sha1 crypto on PHP? Answer: The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1 returns a bit value, and md5 returns a bit value. This is important when avoiding collisions. Answer: Crypto usage in PHP is simple, but that doesn"t mean it"s free. First off, depending on the data that you"re encrypting, you might have reasons to store a bit value in the database instead of the bit value to save on space.

Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5 generation is required. Related Papers. It is a widely-used open source general-purpose scripting language. Especially suited for web development related to dynamic nature of websites.

Which is the latest version of PHP? Who is known as the father of PHP? Rasmus Lerdorf, is considered as the father of PHP. When was PHP developed? You can read full history on php. Name offical website of PHP? What are the extensions of PHP File? What language is PHP written in? The separate program, the PHP interpreter, is itself written in C. C is a compiled language, but it is not compiled to machine code. Instead, it is compiled to a specialist language, byte code, to be run on a virtual machine.

Java is another example of such a setup. What is a PHP File? Files with.



0コメント

  • 1000 / 1000