Sunday, June 12, 2016

nabjquery interview

jQuery Interview Question

A list of top frequently asked jQuery interview questions and answers are given below.

1) What is jQuery?

jQuery is a fast, lightweight, feature-rich client side JavaScript framework. It has provided a much needed boost to JavaScript. Before jQuery, JavaScript codes were lengthy and bigger, even for smaller functionality.

2) Is jQuery a programming language?

jQuery is not a programming language but a well written JavaScript code. It is used to traverse documents, event handling, Ajax interaction and Animation.

3) What is the difference between JavaScript and jQuery?

The simple difference is that JavaScript is a language while jQuery is a built-in library built of JavaScript. jQuery simplifies the use of JavaScript language.

4) Is jQuery replacement of JavaScript?

No, jQuery is not the replacement of JavaScript. jQuery is written on the top of JavaScript and it is a different library. jQuery is lightweight JavaScript library which is used to interact JavaScript and HTML.

5) Why do we use jQuery?

  • It is very easy to learn and use.
  • It is used to develop browser compatible web applications.
  • It improves the performance of an application.
  • It is very fast and extensible.
  • It facilitates you to write minimal lines of codes for UI related functions.
  • It provides a cross-browser support.

6) What are the effects methods used in jQuery?

These are some effects methods used in jQuery:
  • show()
  • hide()
  • toggle()
  • fadeIn()
  • fadeOut()

7) Is it possible that jQuery HTML work for both HTML and XML document?

No, jQuery HTML only works for HTML document. It doesn't work for XML documents.

8) What is $() in jQuery library?

The $() function is an alias of jQuery() function. It is used to wrap any object into jQuery object which later facilitates you to call various method defined jQuery object. You can pass a selector string to $() function and it will return jQuery object which contains an array of all matched DOM elements.

9) Is jQuery library used for server scripting or client scripting?

It is a library for client side Scripting.

10) Is jQuery a W3C standard?

No, jQuery is not a W3C standard.

11) What is the starting point of code execution in jQuery?

$(document).ready() function is the starting point of jQuery code. It is executed when DOM is loaded.

12) What is the basic requirement to start with the jQuery?

You need to make reference of its library to start with jQuery. You can download the latest version of jQuery from jQuery.com.

13) Can you use a special character in place of $ (dollar sign) in jQuery?

Yes.

14) Can you use multiple document.ready() function on the same page?

Yes. You can use any number of document.ready() function on the same page.

15) What is the difference between find and children methods?

Find method is used to find all levels down the DOM tree while children method is used to find single level down the DOM tree.

16) What is a CDN?

CDN stands for Content Delivery Network or Content Distribution Network. It is a large distributed systems of servers deployed in multiple data centers across the internet.

17) What is the goal of CDN and what are the advantages of using CDN?

The main goal of the CDN is to provide content to the end-users with high availability and high performance.
Advantages of using CDN:
  • It reduces the load from the server.
  • It saves bandwidth. jQuery framework is loaded faster from these CDN.
  • If a user visits regularly a site which is using jQuery framework from any of these CDN, it will be cached.

18) How can you use jQuery library in your project?

You can use jQuery library in ASP.Net project from downloading the latest jQuery library from jQuery.com and include the references to the jQuery library file in your HTML/PHP/JSP/Aspx page.
  1. <script src="_scripts/jQuery-1.2.6.js" type="text/javascript"></script>   
  2. <script language="javascript">   
  3. $(document).ready(function() {   
  4. alert('test');   
  5. });   
  6. </script>  

19) What are selectors in jQuery? How many types of selectors in jQuery?

If you want to work with an element on the web page, first you need to find it. Selectors are used to find the HTML elements in jQuery. There are many types of selectors. Some basic selectors are:
  • Name: It is used to selects all elements which match with the given element Name.
  • #ID: It is used to selects a single element which matches with the given ID
  • .Class: It is used to selects all elements which match with the given Class.
  • Universal (*): It is used to selects all elements available in a DOM.
  • Multiple Elements E, F, G: It is used to selects the combined results of all the specified selectors E, F or G.
  • Attribute Selector: It is used to select elements based on its attribute value.

20) What is use of jQuery filter?

: jQuery filter is used to filter the certain values from the object. It filters the result of your original query into specific elements.

21) What are the different types of selectors in jQuery?

There are three types of selectors in jQuery:
  • CSS Selector
  • Custom Selector
  • XPath Selector

22) What is the difference between ID selector and class selector in jQuery?

ID selector and class selector are same like they are used in CSS. ID selector uses ID while class selector uses class to select elements.
If you need to select just one element, use ID selector. If you want to select a group of elements, having same CSS class, use class selector.

23) How to add and remove CSS classes to an element using jQuery?

You can use addclass() jQuery method to add CSS class to an element and removeclass() jQuery method to remove CSS class from an element.

24) Can you write a jQuery code to select all links inside the paragraph?

Yes. You can use <a> tag nested inside paragraph <p> tag to select all links.

25) What is the difference between prop and attr?

attr(): It gets the value of an attribute for the first element in the set of matched element.
prop(): it gets the value of a property for the first element in the set of matched elements. It is introduced in jQuery 1.6.

26) What are the two types of CDNs?

There are two types of CDN:
  • Microsoft: It loads jQuery from AJAX CDN.
  • Google: It loads jQuery from Google libraries API.

27) What is the use of animate function in jQuery?

The animate function is used to apply the custom animation effect to elements. Syntax:
  1. $(selector).animate({params}, [duration], [easing], [callback])  
Here,
  • "param" defines the CSS properties on which you want to apply the animation.
  • "duration" specify how long the animation will run. It can be one of following values : "slow", "fast", "normal" or milliseconds
  • "easing" is the string which specify the function for the transition.
  • "callback" is the function which we want to run once the animation effect is complete.

28) How can you disable jQuery animation?

By using jQuery property "jQuery.fx.off" and setting it to true, you can disable jQuery animation.

nabjavascript interview

avaScript Interview Questions

JavaScript interview questions and answers for provides a list of top 20 interview questions. The frequently asked JavaScript interview questions with answers for beginners and professionals are given below.

1) What is JavaScript?

JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight and cross platform. It is widely used for client side validation. More details...

2) What is the difference between JavaScript and jscript?

Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to avoid the trademark issue.In other words, you can say JScript is same as JavaScript, but it is provided by Microsoft.

3) How to write a hello world example of JavaScript?

A simple example of JavaScript hello world is given below. You need to place it inside the body tag of html.
  1. <script type="text/javascript">  
  2. document.write("JavaScript Hello World!");  
  3. </script>  
More details...

4) How to use external JavaScript file?

I am assuming that js file name is message.js, place the following script tag inside the head tag.
  1. <script type="text/javascript" src="message.js"></script>  
More details...

5) Is JavaScript case sensitive language?

Yes.

6) What is BOM?

BOM stands for Browser Object Model. It provides interaction with the browser. The default object of browser is window.
Browser Object Model

7) What is DOM? What is the use of document object?

DOM stands for Document Object Model. A document object represent the html document. It can be used to access and change the content of html.
Document Object Model

8) What is the use of window object?

The window object is automatically created by the browser that represents a window of a browser.
It is used to display the popup dialog box such as alert dialog box, confirm dialog box, input dialog box etc.
More details...

9) What is the use of history object?

The history object of browser can be used to switch to history pages such as back and forward from current page or another page. There are three methods of history object.
  1. history.back()
  2. history.forward()
  3. history.go(number): number may be positive for forward, negative for backward.
More details...

10) How to write comment in JavaScript?

There are two types of comments in JavaScript.
  1. Single Line Comment: It is represented by // (double forward slash)
  2. Multi Line Comment: It is represented by slash with asterisk symbol as /* write comment here */
More details...

11) How to create function in JavaScript?

To create function in JavaScript, follow the following syntax.
  1. function function_name(){  
  2. //function body  
  3. }  
More details...

12) What are the JavaScript data types?

There are two types of data types in JavaScript:
  1. Primitive Data Types
  2. Non-primitive Data Types
More details...

13) What is the difference between == and ===?

The == operator checks equality only whereas === checks equality and data type i.e. value must be of same type.

14) How to write html code dynamically using JavaScript?

The innerHTML property is used to write the HTML code using JavaScript dynamically. Let's see a simple example:
  1. document.getElementById('mylocation').innerHTML="<h2>This is heading using JavaScript</h2>";   
More details...

15) How to write normal text code using JavaScript dynamically?

The innerText property is used to write the simple text using JavaScript dynamically. Let's see a simple example:
  1. document.getElementById('mylocation').innerText="This is text using JavaScript";   
More details...

16) How to create objects in JavaScript?

There are 3 ways to create object in JavaScript.
  1. By object literal
  2. By creating instance of Object
  3. By Object Constructor
Let's see a simple code to create object using object literal.
  1. emp={id:102,name:"Rahul Kumar",salary:50000}   
More details...

17) How to create array in JavaScript?

There are 3 ways to create array in JavaScript.
  1. By array literal
  2. By creating instance of Array
  3. By using an Array constructor
Let's see a simple code to create array using object literal.
  1. var emp=["Shyam","Vimal","Ratan"];    
More details...

18) What does the isNaN() function?

The isNan() function returns true if the variable value is not a number.

19) What is the output of 10+20+"30" in JavaScript?

3030 because 10+20 will be 30. If there is numeric value before and after +, it is treated is binary + (arithmetic operator).

20) What is the output of "10"+20+30 in JavaScript?

102030 because after a string all the + will be treated as string concatenation operator (not binary +).

21) Difference between Client side JavaScript and Server side JavaScript?

Client side JavaScript comprises the basic language and predefined objects which are relevant to running java script in a browser. The client side JavaScript is embedded directly by in the HTML pages. This script is interpreted by the browser at run time.
Server side JavaScript also resembles like client side java script. It has relevant java script which is to run in a server. The server side JavaScript are deployed only after compilation.

22) In which location cookies are stored on the hard disk?

The storage of cookies on the hard disk depends on OS and the browser.
The Netscape navigator on Windows uses cookies.txt file that contains all the cookies. The path is : c:\Program Files\Netscape\Users\username\cookies.txt
The Internet Explorer stores the cookies on a file username@website.txt. The path is: c:\Windows\Cookies\username@Website.txt.

23) What is the real name of JavaScript?

The original name was Mocha, a name chosen by Marc Andreessen, founder of Netscape. In September of 1995, the name was changed to LiveScript. In December 1995, after receiving a trademark license from Sun, the name JavaScript was adopted.

24) What is the difference between undefined value and null value?

Undefined value: A value that is not defined and has no keyword is known as undefined value. For example:
  1. int number;//Here, number has undefined value.  
Null value: A value that is explicitly specified by the keyword "null" is known as null value. For example:
  1. String str=null;//Here, str has a null value.  

24) How to set the cursor to wait in JavaScript?

The cursor can be set to wait in JavaScript by using the property "cursor". The following example illustrates the usage:
  1. <script>  
  2. window.document.body.style.cursor = "wait";   
  3. </script>  

25) What is this?

  1. var myArray = [[[]]];  
Ans: Three dimensional array.

26) Are Java and JavaScript same?

No, Java and JavaScript are the two different languages. Java is a robust, secured and object-oriented programming language whereas JavaScript is a client side scripting language with some limitations.

27) What is negative infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

28) What is difference between View state and Session state?

"View state" is specific to a page in a session whereas "Session state" is specific to a user or browser that can be accessed across all pages in the web application.

29) What are the pop up boxes available in JavaScript?

  • Alert Box
  • Confirm Box
  • Prompt Box

30) How can we detect OS of the client machine using JavaScript?

The navigator.appVersion string can be used to detect the operating system on the client machine.

31) How to submit a form using JavaScript by clicking a link?

Let's see the JavaScript code to submit form on clicking the link.
  1. <form name="myform" action="index.php">  
  2. Search: <input type='text' name='query' />  
  3. <a href="javascript: submitform()">Search</a>  
  4. </form>  
  5. <script type="text/javascript">  
  6. function submitform()  
  7. {  
  8.   document.myform.submit();  
  9. }  
  10. </script>  

32) Is JavaScript faster than ASP script?

Yes, because it doesn't require web server's support for execution.

33) How to change the background color of HTML document using JavaScript?

  1. <script type="text/javascript">  
  2. document.body.bgColor="pink";  
  3. </script>  

34) How to handle exceptions in JavaScript?

By the help of try/catch block, we can handle exceptions in JavaScript. JavaScript supports try, catch, finally and throw keywords for exception handling.

35) How to validate a form in JavaScript?

Visit here: JavaScript form validation.

36) How to validate email in JavaScript?

Visit here: JavaScript Email validation.

nabphpinterview2

PHP Interview Questions

There is given PHP interview questions and answers that has been asked in many companies. Let's see the list of top PHP interview questions.

1) What is PHP?

PHP stands for Hypertext Preprocessor. It is an open source server-side scripting language that is widely used for web development. It supports many databases like MySQL, Oracle, Sybase, Solid, PostgreSQL, generic ODBC etc.
More Details...

2) What is PEAR in PHP?

PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries.
It also provide a command line interface to install "packages" automatically.

3) Who is known as the father of PHP?

Rasmus Lerdorf

4) What was the old name of PHP?

Personal Home Page.

5) Explain the difference b/w static and dynamic websites?

In static websites, content can't be changed after running the script. You can't change anything in the site. It is predefined.
In dynamic websites, content of script can be changed at the run time. Its content regenerated every time the user visit or reload. Google, yahoo and every search engine is the example of dynamic website.

6) What is the name of scripting engine in PHP?

The scripting engine that powers PHP is called Zend Engine 2.

7) Explain the difference between PHP4 and PHP5.

PHP4 doesn't support oops concept and uses Zend Engine 1.
PHP5 supports oops concept and uses Zend Engine 2.

8) What are the methods of form submitting in PHP?

There are two methods GET and POST.

9) What is a session?

PHP Engine creates a logical object to preserve data across subsequent HTTP requests, which is known as session.
Sessions generally store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same user.
Simply, it maintains data of an user (browser).
More Details...

10) What is the method to register a variable into a session?

  1. <?php  
  2. Session_register($ur_session_var);  
  3. ?>  

11) What are the encryption functions in PHP?

CRYPT() and MD5()

12) What are the different types of errors in PHP?

There are 3 types of error 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.

13) What is the difference between $message and $$message?

$message stores variable data while $$message is used to store variable of variables.
$message stores fixed data whereas the data stored in $$message may be changed dynamically.

14) What is the difference between "echo" and "print" in PHP?

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.

15) How do you connect MySQL database with PHP?

There are two methods to connect MySQL database with PHP. Procedural and object oriented style.

16) 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.

17) Which programming language does PHP resemble to?

PHP has borrowed its syntax from Perl and C.

18) What is the method to execute a PHP script from the command line?

You should just run the PHP command line interface (CLI) and specify the file name of the script to be executed as follows.

19) What is the use of count() function in PHP?

Count() function is used to count total elements in the array, or something an object.

20) 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 in the text file format 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.

21) How can you retrieve a cookie value?

  1. echo $_COOKIE ["user"];  

22) What are the different loops in PHP?

For, while, do-while and for each.

23) 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 function.

24) What is the array in PHP?

Array is used to store multiple values in single value. In PHP, it orders maps of pairs of keys and values. It stores the collection of data type.

25) How can you submit a form without a submit button?

You can use JavaScript submit() function to submit the form without explicitly clicking any submit button.

26) What does isset() function?

The isset() function checks if the variable is defined and not null.

27) How to get the length of string?

The strlen() function is used to get the length of string.

28) How can you send email in PHP?

The mail() function is used to send email in PHP.
  1. bool mail($to,$subject,$message,$header);    
More Details...

29) What is the difference between indexed and associative array?

The indexed array holds elements in an indexed form which is represented by number starting from 0 and incremented by 1. For example:
  1. $season=array("summer","winter","spring","autumn");    
The associative array holds elements with name. For example:
  1. $salary=array("Sonoo"=>"350000","John"=>"450000","Kartik"=>"200000");    
More Details...

30) How to upload file in PHP?

The move_uploaded_file() function is used to upload file in PHP.
  1. bool move_uploaded_file ( string $filename , string $destination )    
More Details...

31) How to download file in PHP?

The readfile() function is used to download file in PHP.
  1. int readfile ( string $filename )     
More Details...

32) How to delete file in PHP?

The unlink() function is used to delete file in PHP.
  1. bool unlink (string $filename)      
More Details...

33) How to create connection in PHP?

The mysqli_connect() function is used to create connection in PHP.
  1. resource mysqli_connect (server, username, password)       
More Details...

34) How to stop the execution of PHP script?

The exit() function is used to stop the execution of PHP script.

35) What are the popular Content Management Systems (CMS) in PHP?

  • WordPress
  • Joomla
  • Magento
  • Drupal etc.

36) What are the popular frameworks in PHP?

  • CakePHP
  • CodeIgniter
  • Yii 2
  • Symfony
  • Zend Framework etc.

nabmysqlinterview

MySQL Interview Questions


1) What is MySQL?

MySQL is a multithreaded, multi-user SQL database management system which has more than 11 million installations. This is the world's second most popular and widely used open source database.

2) In which language MySQL is written?

MySQL is written in C and C++ and its SQL parser is written in yacc.

3) What are the technical specification of MySQL?

MySQL has the following technical specifications -
  • Flexible structure
  • High performance
  • Manageable and easy to use
  • Replication and high availability
  • Security and storage management

4) How many Triggers are possible in MySQL?

There are only six Triggers allowed to use in MySQL database.
  1. Before Insert
  2. After Insert
  3. Before Update
  4. After Update
  5. Before Delete
  6. After Delete

5) What is heap table?

Tables that are present in memory is known as HEAP tables. When you create a heap table in MySQL, you should need to specify the TYPE as HEAP. These tables are commonly known as memory tables. They are used for high speed storage on temporary basis. They do not allow BLOB or TEXT fields.

6) What is BLOB and TEXT in MySQL?

BLOB is an acronym stands for binary large object. It is used to hold a variable amount of data.
There are four types of BLOB.
  1. TINYBLOB
  2. BLOB
  3. MEDIUMBLOB
  4. LONGBLOB
The differences among all these are the maximum length of values they can hold.
TEXT is case-insensitive BLOB. TEXT values are non-binary strings (character string). They have a character set and values are stored and compared based on the collation of the character set.
There are four types of TEXT.
  1. TINYTEXT
  2. TEXT
  3. MEDIUMTEXT
  4. LONGTEXT

7) What is a trigger in MySQL?

A trigger is a set of codes that executes in response to some events.

8) What is the difference between heap table and temporary table?

Heap tables:
Heap tables are found in memory. They are used for high speed storage on temporary basis. They do not allow BLOB or TEXT fields.
Heap tables do not support AUTO_INCREMENT.
Indexes should be NOT NULL.
Temporary tables:
The temporary tables are used to keep the temporary data. Sometimes it is very useful in cases to keep temporary data. Temporary table is deleted after current client session terminates.
Main differences:
The heap tables are shared among clients while temporary tables are not shared.
Heap tables are just another storage engine, while for temporary tables you need a special privilege (create temporary table).

9) What is the difference between FLOAT and DOUBLE?

FLOAT stores floating point numbers with accuracy up to 8 places and allocates 4 bytes, on the other hand DOUBLE stores floating point numbers with accuracy up to 18 places and allocates 8 bytes.

10) What are the advantages of MySQL in comparison to Oracle?

  1. MySQL is a free, fast, reliable, open source relational database while Oracle is expensive, although they have provided Oracle free edition to attract MySQL users.
  2. MySQL uses only just under 1 MB of RAM on your laptop while Oracle 9i installation uses 128 MB.
  3. MySQL is great for database enabled websites while Oracle is made for enterprises.
  4. MySQL is portable.

11) What are the disadvantages of MySQL?

  1. MySQL is not so efficient for large scale databases.
  2. It does not support COMMIT and STORED PROCEDURES functions version less than 5.0.
  3. Transactions are not handled very efficiently.

12) What is the difference between CHAR and VARCHAR?

1) CHAR and VARCHAR are differ in storage and retrieval.
2) CHAR column length is fixed while VARCHAR length is variable.
3) The maximum no. of character CHAR data type can hold is 255 character while VARCHAR can hold up to 4000 character.
4) CHAR is 50% faster than VARCHAR.
5) CHAR uses static memory allocation while VARCHAR uses dynamic memory allocation.

13) What is the difference between MySQL_connect and MySQL_pconnect?

Mysql_connect:
  1. It opens a new connection to the database.
  2. Every time you need to open and close database connection, depending on the request.
  3. Opens page every time when it loaded.
Mysql_pconnect:
  1. In Mysql_pconnect, "p" stands for persistent connection so it opens the persistent connection.
  2. the database connection can not be closed.
  3. it is more useful if your site has more traffic because there is no need to open and close connection frequently and every time when page is loaded.

14) What does " i_am_a_dummy flag" do in MySQL?

The " i_am_a_dummy flag" enables MySQL engine to refuse any UPDATE or DELETE statement to execute if the WHERE clause is not present.

15) How to get the current date in MySQL?

To get current date, use the following syntax:
  1. SELECT CURRENT_DATE();  

16) What are the security alerts while using MySQL?

Install antivirus and configure the operating system's firewall.
Never use the MySQL Server as the UNIX root user.
Change root username and password
Restrict or disable remote access.

17) How to change a password for an existing user via Mysqladmin?

Mysqladmin -u root -p password "newpassword".

18) What is the difference between Unix timestamps and MySQL timestamps?

Actually both Unix timestamp and MySQL timestamp are stored as 32-bit integers but MySQL timestamp is represented in readable format of YYYY-MM-DD HH:MM:SS format.

19) How to display Nth highest salary from a table in a MySQL query?

Let us take a table named employee.
To find Nth highest salary is:
  1. select distinct(salary) from employee order by salary desc limit n-1,1  
if you want to find 3rd largest salary:
  1. select distinct(salary) from employee order by salary desc limit 2,1  

20) What is MySQL default port number?

MySQL default port number is 3306.

21) What is REGEXP?

REGEXP is a pattern match using regular expression. Regular expression is a powerful way of specifying a pattern for a complex search.

22) How many columns can you create for an index?

You can create maximum of 16 indexed columns for a standard table.

23) What is the difference between NOW() and CURRENT_DATE()?

NOW() command is used to show current year, month, date with hours, minutes and seconds while CURRENT_DATE() shows the current year with month and date only.

24) What is the query to display top 20 rows?

  1. SELECT * FROM table_name LIMIT 0,20;  

25) Write a query to display current date and time?

If you want to display current date and time, use -
  1. SELECT NOW();  
  2. If you want to display current date only, use -  
  3. SELECT CURRENT_DATE();  

26) What is save point in MySQL?

A defined point in any transaction is known as savepoint.
SAVEPOINT is a statement in MySQL which is used to set a named transaction save point with a name of identifier.

27) What is SQLyog?

SQLyog program is the most popular GUI tool for admin. It is the most popular MySQL manager and admin tool. It combines the features of MySQL administrator, phpMyadmin and others MySQL front ends and MySQL GUI tools.

28) How do you backup a database in MySQl?

It is easy to backing up data with phpMyAdmin. Select the database you want to backup by clicking the database name in the left hand navigation bar. Then click the export button and make sure that all tables are highlighted that you want to backup. Then specify the option you want under export and save the output.

nabphpinterview

to check the path to php.ini.
The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as 'escaping to PHP.'
Whitespace is the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage returns endoflinecharacters
. PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row.one whitespace character is the same as many such characters.
Yes!
Here are the most important things to know about variables in PHP.
  • All variables in PHP are denoted with a leading dollar sign $
  • .
  • The value of a variable is the value of its most recent assignment.
  • Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.
  • Variables can, but do not need, to be declared before assignment.
  • Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters.
  • Variables used before they are assigned have default values.
  • PHP does a good job of automatically converting types from one to another when necessary.
  • PHP variables are Perl-like.
PHP has a total of eight data types which we use to construct our variables −
  • Integers − are whole numbers, without a decimal point, like 4195.
  • Doubles − are floating-point numbers, like 3.14159 or 49.1.
  • Booleans − have only two possible values either true or false.
  • NULL − is a special type that only has one value: NULL.
  • Strings − are sequences of characters, like 'PHP supports string operations.'
  • Arrays − are named and indexed collections of other values.
  • Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
  • Resources − are special variables that hold references to resources external to PHP suchasdatabaseconnections
  • .
Rules for naming a variable are following −
  • Variable names must begin with a letter or underscore character.
  • A variable name can consist of numbers, letters, underscores but you cannot use characters like + , - , % , ,
  • . & , etc
Here are the rules for determine the "truth" of any value not already of the Boolean type −
  • If the value is a number, it is false if exactly equal to zero and true otherwise.
  • If the value is a string, it is false if the string is empty haszerocharacters
  • or is the string "0", and is true otherwise.
    • .
    • Don't use double as Booleans.

    NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it like this −
    $my_var = NULL;
    The special constant NULL is capitalized by convention, but actually it is case insensitive; you could just as well have typed −
    $my_var = null;
    A variable that has been assigned NULL has the following properties:
    It evaluates to FALSE in a Boolean context.
    It returns FALSE when tested with IsSet
    function.
    To define a constant you have to use define
    function and to retrieve the value of a constant, you have to simply specifying its name. Unlike with variables, you do not need to have a constant with a $.
    As indicated by the name, this function will return the value of the constant. This is useful when you
    want to retrieve value of a constant, but you do not know its name, i.e. It is stored in a variable or returned by a function.
    <?php
    define("MINSIZE", 50);
    echo MINSIZE;
    echo constant("MINSIZE"); // same thing as the previous line
    ?>
    Only scalar data boolean,integer,floatandstring
    can be contained in constants.
    • There is no need to write a dollar sign $
    • function.
    • Constants may be defined and accessed anywhere without regard to variable scoping rules.
    • Once the Constants have been set, may not be redefined or undefined.

    PHP provides a large number of predefined constants to any script which it runs known as magic constants.
    _LINE_ − The current line number of the file.
    _FILE_ − The full path and filename of the file. If used inside an include,the name of the included file is returned. Since PHP 4.0.2, _FILE_ always contains an absolute path whereas in older versions it contained relative path under some circumstances.
    _FUNCTION_ − The function name. AddedinPHP4.3.0
    As of PHP 5 this constant returns the function name as it was declared casesensitive
    . In PHP 4 its value is always lowercased.
    _CLASS_ − The class name. AddedinPHP4.3.0
    As of PHP 5 this constant returns the class name as it was declared casesensitive
    . In PHP 4 its value is always lowercased.
    _METHOD_ − The class method name. AddedinPHP5.0.0
    The method name is returned as it was declared casesensitive
    .
    break terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.
    continue causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
    The foreach statement is used to loop through arrays. For each pass the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass next element will be processed.
    foreach (array as value)
    {
        code to be executed;
    }
    Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.
    Associative array − An array with strings as index. This stores element values in association with key values rather than in a strict linear index order.
    Multidimensional array − An array containing one or more arrays and values are accessed using multiple indices.
    To concatenate two string variables together, use the dot .
    operator −
    <?php
    $string1="Hello World";
    $string2="1234";
    echo $string1 . " " . $string2;
    ?>
    This will produce following result −
    Hello World 1234
    The strlen
    function is used to find the length of a string. Let's find the length of our string "Hello world!" −
    <?php
    echo strlen("Hello world!");
    ?>
    This will produce following result −
    12
    The strpos
    function is used to search for a string or character within a string. If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE. Let's see if we can find the string "world" in our string −
    <?php
    echo strpos("Hello world!","world");
    ?>
    This will produce following result −
    6
    PHP provides a function getenv
    to access the value of all the environment variables.
    One of the environemnt variables set by PHP is HTTP_USER_AGENT which identifies the user's browser and operating system.
    The PHP rand
    function is used to generate a random number. This function can generate numbers with-in a given range. The random number generator should be seeded to prevent a regular pattern of numbers being generated. This is achieved using the srand
    function that specifiies the seed number as its argument.
    The PHP default variable $_PHP_SELF is used for the PHP script name and when you click "submit" button then same PHP script will be called.
    The PHP header
    function supplies raw HTTP headers to the browser and can be used to redirect it to another location. The redirection script should be at the very top of the page to prevent any other part of the page from loading. The target is specified by the Location: header as the argument to the header function. After calling this function the exit
    function can be used to halt parsing of rest of the code.
    The HTTP header will be different from the actual header where we send Content-Type as text/html\n\n. In this case content type will be application/octet-stream and actual file name will be concatenated alongwith it. For example,if you want make a FileName file downloadable from a given link then its syntax will be as follows.
    #!/usr/bin/perl
    # HTTP Header
    print "Content-Type:application/octet-stream; name=\"FileName\"\r\n";
    print "Content-Disposition: attachment; filename=\"FileName\"\r\n\n";
    # Actual File Content
    open( FILE, "<FileName" );
    while(read(FILE, $buffer, 100) )
    {
       print("$buffer");
    }
    The PHP provides $_GET associative array to access all the sent information using GET method.
    The PHP provides $_POST associative array to access all the sent information using POST method.
    The PHP REQUESTvariablecontainsthecontentsofboth
    _GET, POST,and_COOKIE. We will discuss COOKIEvariablewhenwewillexplainaboutcookies.ThePHP
    _REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.
    array
    − Creates an array.
    sort
    − Sorts an array.
    Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.
    <?php
    $variable = "name";
    $literally = 'My $variable will not print!\\n';
    print($literally);
    print "<br />";
    $literally = "My $variable will print!\\n";
    print($literally);
    ?>
    This will produce following result −
    My $variable will not print!\n
    My name will print
    To concatenate two string variables together, use the dot .
    operator.
    <?php
    $string1="Hello World";
    $string2="1234";
    echo $string1 . " " . $string2;
    ?>
    This will produce following result −
    Hello World 1234
    The PHP REQUESTvariablecontainsthecontentsofboth
    _GET, POST,and_COOKIE. We will discuss COOKIEvariablewhenwewillexplainaboutcookies.ThePHP
    _REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.
    There are two PHP functions which can be used to included one PHP file into another PHP file.
    • The include
    • Function
    Function and require
    If there is any problem in loading a file then the require
    function generates a fatal error and halt the execution of the script whereas include
    function generates a warning but the script will continue execution.
    The PHP fopen
    function is used to open a file. It requires two arguments stating first the file name and then mode in which to operate. "r" mode opens the file for reading only and places the file pointer at the beginning of the file.
    Once a file is opened using fopen
    function it can be read with a function called fread
    . This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.
    The files's length can be found using the filesize
    function which takes the file name as its argument and returns the size of the file expressed in bytes.
    File's existence can be confirmed using file_exist
    function which takes file name as an argument.
    Yes! You can set a parameter to have a default value if the function's caller doesn't pass it.
    PHP provided setcookie
    function to set a cookie. This function requires upto six arguments and should be called before <html> tag. For each cookie this function has to be called separately.
    setcookie(name, value, expire, path, domain, security);
    PHP provides many ways to access cookies. Simplest way is to use either COOKIEor
    HTTP_COOKIE_VARS variables.
    You can use isset
    function to check if a cookie is set or not.
    To delete a cookie you should call setcookie
    with the name argument only.
    A PHP session is easily started by making a call to the session_start
    function.This function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start
    at the beginning of the page.
    Session variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session.
    Make use of isset
    function to check if session variable is already set or not.
    Here is the example to unset a single variable −
    <?php
       unset($_SESSION['counter']);
    ?>
    A PHP session can be destroyed by session_destroy
    function.
    PHP makes use of mail
    function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters.
    mail( to, subject, message, headers, parameters );
    This is a global PHP variable. This variable is an associate double dimension array and keeps all the information related to uploaded file.
    Using $_FILES['file']['tmp_name'] − it provides access to the uploaded file in the temporary directory on the web server.
    Using $_FILES['file']['name'] − it provides the actual name of the uploaded file.
    Using $_FILES['file']['size'] − it provides the size in bytes of the uploaded file.
    Using $_FILES['file']['type'] − it provides the MIME type of the uploaded file.
    Using $_FILES['file']['error'] − it provides the error code associated with this file upload.
    $GLOBALS − Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables.
    $_SERVER − This is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these. See next section for a complete list of all the SERVER variables.
    $_COOKIE − An associative array of variables passed to the current script via HTTP cookies.
    $_SESSION − An associative array containing session variables available to the current script.
    $_PHP_SELF − A string containing PHP script file name in which it is called.
    phperrormsg
    php_errormsg is a variable containing the text of the last error message generated by PHP.
    ereg
    − The ereg
    function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.
    eregi
    − The eregi
    function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive.
    The split
    function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in string.
    preg_match
    - The preg_match
    function searches string for pattern, returning true if pattern exists, and false otherwise.
    The preg_split
    function operates exactly like split
    , except that regular expressions are accepted as input parameters for pattern.
    Using getMessage
    method of Exception class which returns the message of exception.
    Using getCode
    method of Exception class which returns the code of exception.
    Using getFile
    method of Exception class which returns source filename.
    Using getLine
    method of Exception class which returns source line.
    Using getTrace
    method of Exception class which returns array of the backtrace.
    Using getTraceAsString
    method of Exception class which returns formated string of trace.
    PHP's time
    function gives you all the information that you need about the current date and time. It requires no arguments but returns an integer.
    The function getdate
    optionally accepts a time stamp and returns an associative array containing information about the date. If you omit the time stamp, it works with the current time stamp as returned by time
    .
    The date
    function returns a formatted string representing a date. You can exercise an enormous amount of control over the format that date
    returns with a string argument that you must pass to it.
    PHP provides mysql_connect function to open a database connection.
    connection mysql_connect(server,user,passwd,new_link,client_flag);
    PHP uses mysql_query function to create a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.
    bool mysql_query( sql, connection );
    Its simplest function mysql_close PHP provides to close a database connection. This function takes connection resource returned by mysql_connect function. It returns TRUE on success or FALSE on failure.
    bool mysql_close ( resource $link_identifier );
    If a resource is not specified then last opend database is closed.
    PHP 5's new SimpleXML module makes parsing an XML document, well, simple. It turns an XML document into an object that provides structured access to the XML. To create a SimpleXML object from an XML document stored in a string, pass the string to simplexml_load_string
    . It returns a SimpleXML object.
    Yes!
    PHP provides a special function called __construct
    to define a constructor. You can pass as many as arguments you like into the constructor function.
    Like a constructor function you can define a destructor function using function __destruct
  • Values of type NULL are always false.
  • If the value is an array, it is false if it contains no other values, and it is true otherwise. For an object, containing a value means having a member variable that has been assigned a value.
  • Valid resources are true althoughsomefunctionsthatreturnresourceswhentheyaresuccessfulwillreturnFALSEwhenunsuccessful
  • before a constant, where as in Variable one has to write a dollar sign.
  • Constants cannot be defined by simple assignment, they may only be defined using the define
  • Function
  • The require