CollExInfo.com
Page 1
PHP
Question: What is PHP? Answer: * PHP stands for Hypertext Preprocessor. * PHP scripts run inside Apache server or Microsoft IIS. * PHP and Apache server are free. * PHP is the most used server side scripting language. * PHP files contain PHP scripts and HTML. * PHP files have the extension “php”, “php3”, “php4”, or “phtml”. Question: When to use PHP? Answer: PHP is Scripting Language and can be used when: Creating Web pages that contain dynamic contents. Responding to HTML forms. Accessing databases. Securing data. Question: Why PHP is Better choice among the other scripting languages? Answer: 1.PHP is easy to learn. 2. PHP is free. 3. PHP can run on Windows and UNIX servers. 4. PHP is very fast. Question: How to embed PHP code in a File? Answer: To embed PHP code inside a file, it has to be inside a special set of opening and closing tags. PHP supports the following tags sets: 1. Opening (< ?php) and closing (? >) 2. Opening (< ?) and closing (? >) 3. Opening (< %) and closing (% >) 4. Opening (< script language=”php” >) and closing (< /script >) Example: < html > …..< head > ……….< title >Sample document< /title > …..< /head > …..< body > ……….< ?php ...............echo “Sample text”; ..........? > …..< /body > < /html >
CollExInfo.com
CollExInfo.com
Page 2
PHP
Question: Explain PHP Data Types in detail? Answer: PHP stores whole numbers in a platform-dependent range. This range is typically that of 32-bit signed integers. Portable code should not assume that values outside this range can be represented in an integer variable. Integer variables can be assigned using decimal (positive and negative), octal and hexadecimal notations. Real numbers are also stored in a platform-specific range. They can be specified using floating point notation, or two forms of Scientific notation. PHP has a native Boolean type, named “Boolean”, similar to the native Boolean types in Java and C++. Using the Boolean type conversion rules, non-zero values can be interpreted as true and zero as false, as in P e r l and C. The Null data type represents a variable that has no value. The only value in the Null data type is NULL. Arrays are heterogeneous, meaning a single array can contain objects of more than one type. They can contain any type that PHP can handle, including resources, objects, and even other arrays. Order is preserved in lists of values and in hashes with both keys and values, and the two can be intermingled. Variables of type “resource” represent references to resources from external sources. These are typically created by functions from a particular extension, and can only be processed by functions from the same extension. Examples include file, image and database resources.
Question: What are Scripts and Files? Answer: A script may include many files, this enables PHP coders to write some of the code once, and use it in many scripts, to include an external file into your script, and you can use one of the following: 1. Include: reads the external file, and interprets it, if the external file can‟t be found, a warning is produced, and the execution continues. 2. Require: the same as includes, but it causes the execution to stop. 3. Include_once: works the same way as include, but the included file will be interpreted just once, at the first time it‟s included, if it‟s included again in the same file, it won‟t be interpreted again. 4. Require_once: the same as require, but also interpreted once like include_once.
Question: Is it possible manipulating visual objects in PHP? Answer: Generally it is, but as PHP is mostly used as a web scripting language it runs in the web servers context, thus visual objects will never appear on the servers desktop. If you use PHP for application scripting e.g. in conjunction with PHP-GTK there is no limitation in accessing and manipulating visual objects through COM.
CollExInfo.com
CollExInfo.com
Page 3
PHP
Question: What is the difference between htmlentities () and htmlspecialchars ()? Answer: htmlspecialchars only takes care of <; >, single quote, double quote and ampersand whereas htmlentities translates all occurrences of character sequences that have some other meaning in HTML. Question: Compare PHP and PERL? Answer: The biggest advantage of PHP over P E R L is that PHP was designed for scripting for the web where P E R L was designed to do a lot more and can because of this get very complicated. The flexibility / complexity of P E R L make it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format without losing flexibility. PHP is easier to integrate into existing HTML than P E R L. PHP has pretty much all the „good‟ functionality of P E R L: constructs, syntax and so on, without making it as complicated as P E R L can be. P E R L is a very tried and true language, it‟s been around since the late eighties, but PHP is maturing very quickly. Question: Question: Explain the difference between echo, print and printf. Answer: echo, print and printf are used for printing strings but the basic difference between them is: echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. And you can pass multiple parameters to echo, like: And it will output the string “Welcome Jack” Whereas print does not take multiple parameters, it is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it‟s the slowest way to print out data out of echo, print and printf.
Question: How do I find out the number of parameters passed into function? Answer: func_num_args () function returns the number of parameters passed in. Question: What is the difference between md5 (), crc32 () and sha1 () crypto on PHP? Answer: All these functions generate a hash code and the basic difference among them is the length of the generated hash. crc32 () gives 32 bit code sha1 () gives 128 bit code md5 () gives 160 bit code (generally used to avoid collisions)
CollExInfo.com
CollExInfo.com
Page 4
PHP
Question: What is the difference between include and require? Answer: The basic difference is how they handle failures. If the file is not found by require (), it will cause a fatal error and halt the execution of the script. If the file is not found by include (), a warning will be issued, but execution will continue. Question: What does & beside argument mean in function declaration of e.g. asort ()? Answer: The biggest advantage of PHP over P E R L is that PHP was designed for scripting for the web where P E R L was designed to do a lot more and can because of this get very complicated. The flexibility / complexity of P E R L make it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format without losing flexibility. PHP is easier to integrate into existing HTML than P E R L. PHP has pretty much all the „good‟ functionality of P E R L: constructs, syntax and so on, without making it as complicated as P E R L can be. P E R L is a very tried and true language, it‟s been around since the late eighties, but PHP is maturing very quickly.
Question: Compare PHP and Cold Fusion. Answer: PHP is commonly said to be faster and more efficient for complex programming tasks and trying out new ideas. PHP is generally referred to as more stable and less resource intensive as well. Cold Fusion has better error handling, database abstraction and date parsing although database abstraction is addressed in PHP 4. Another thing that is listed as one of Cold Fusion‟s strengths is its excellent search engine, but it has been mentioned that a search engine is not something that should be included in a web scripting language. PHP runs on almost every platform there is; Cold Fusion is only available on Win32, Solaris, Linux and HP/UX. Cold Fusion has a good IDE and is generally easier to get started with, whereas PHP initially requires more programming knowledge. Cold Fusion is designed with non-programmers in mind, while PHP is focused on programmers. Question: If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format that is easier to use? Answer: The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like. So let's say we have $date = "Tuesday, February 14, 2006 @ 10:39 am"; In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function. So we have $date = str_replace("@ ","",$date); $date = strtotime($date); now $date is a timestamp and we can say: echo date("d M Y",$date); CollExInfo.com
CollExInfo.com
Page 5
PHP
Question: How can I maintain the count of how many persons have hit my site? Answer: Remove that html comment and execute it. Question: How do I instantiate a bean whose constructor accepts parameters using the use Bean tag? Answer: Consider the following bean: package bar; public class FooBean { public FooBean(SomeObj arg) { ... } //getters and setters here } The only way you can instantiate this bean within your JSP page is to use a scriptlet. For example, the following snippet creates the bean with session scope: < % SomeObj x = new SomeObj(...); bar.FooBean foobar = new FooBean(x); session.putValue("foobar",foobar); %> You can now access this bean within any other page that is part of the same session as: &l;% bar.FooBean foobar = session.getValue("foobar"); %> To give the bean "application scope", you will have to place it within the ServletContext as: <% application.setAttribute("foobar",foobar); %> To give the bean "request scope", you will have to place it within the request object as: <% request.setAttribute("foobar",foobar); %> If you do not place the bean within the request, session or application scope, the bean can be accessed only within the current JSP page (page scope). Once the bean is instantiated, it can be accessed in the usual way: jsp:getProperty name="foobar" property="someProperty"/ jsp:setProperty name="foobar" property="someProperty" value="someValue"/ Question: How I can get ip address? Answer: PHP makes REMOTE_ADDR and REMOTE_HOST available for our use; they live within the SERVER arrays. So: REMOTE_ADDR - the IP address of the client. REMOTE_HOST - the host address of the client, if available. Question: what is difference between mysql_connect and mysql_pconnect? Answer: Mysql_connect opens up a database connection every time a page is loaded. mysql_pconnect opens up a connection, and keeps it open across multiple requests.
CollExInfo.com
CollExInfo.com
Page 6
PHP
Mysql_pconnect uses less resource, because it does not need to establish a database connection every time a page is loaded. Question: How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working) Answer: For this we can use the session object ($_SESSION) t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages. Question: How i can make a chat page in php in simple? Answer: First of all we have to make one .txt file ...then open it in write mode then write something in message box that will written in that file ...the another user also open that file and write the file with the message box....Also open the file in read mod in side window to see what the another user is write ...IN this way we can make simple chat file with php. Question: What is the difference between echo and print statement? Answer: Difference1: echo () can take multiple expressions, Print cannot take multiple expressions. echo has the slight performance advantage because it doesn't have a return value. True, echo is a little bit faster. Question: What is difference between PHP and HTML? Answer: HTML files are requested by browser, and returned by server. PHP files are requested by browser, and executed by the server to output a plain HTML that is returned to the browser.
CollExInfo.com