Use HTML5 On Your Website

Detect HTML5 usage

If you want to see that a website is using HTML5 elements or not, you only need to view the source of the website.
If the source code starts with the following declaration.


Then, website was marked up with HTML5.

By using the HTML5 DocType, you can let the browser know what to expect from your document.HTML4 required a DocType reference to a DTD (doc type declaration), and there were three different DTD’s that could be used but HTML5 doesn’t require such a reference.


Remove Internet Explorer HTML5 Compatibility Issues

Microsoft IE9 supports HTML5, but there are still so many people using MSIE 7 and 8 and even MSIE 6.Add below HTML5 enabling script to allow developers to use any HTML5 element on their page. It should place within the <HEAD> tags, and is referenced like this:


<!–[if lt IE 9]>
<script src=””></script>


HTML5 Element Detection Techniques

When browser renders a web page, it constructs a Document Object Model (DOM), a collection of objects that represent the HTML elements on the page. Every html element is represented in the DOM by a different object. (There are also global objects, like window and document, that arenā€™t tied to specific elements.)

All DOM objects share a set of common properties, but some objects have more than others. In browsers that support HTML5 features, certain objects will have unique properties. Let’s discuss, which features are supported.

There are four basic techniques can be used to detect whether a browser supports a particular feature or not.

1.Check if a certain property exists on a global object (such as window or navigator).
E.g: test for geolocation support


2.Create an element, and then check if a certain property exists on that element.
E.g: test for canvas support


3.Create an element, check if a certain method exists on that element, then call the method and check the value it returns.
E.g: test which video formats are supported


4.Create an element, set a property to a certain value, and then check if the property has retained its value.
E.g: test which <input> types are supported


Modernizr can be used to detect these easily as
Modernizr is an open source, MIT-licensed JavaScript library that detects support for many HTML5 & CSS3 features. You should always use the latest version of this. To use it, include the following <script> element at the top of your page.
<script src=”modernizr.min.js”></script>


HTML5 Form Enhancements (New elements)

Autofocus Using HTML5
<input id=”example” name=”example” type=”text” autofocus />

Placeholders Using HTML5
<input id=”example1″ name=”example1″ type=”text” placeholder=”Your Text” />

Editable Content Using HTML5’s contenteditable
<p contenteditable=”true”>Put your mouse pointer in this text and you can update it!</p>

Also, it has also introduced some new elements as below:



HTML5 also defines new input types that you can use in your forms.

<input type=”search”> for search box
<input type=”date”> for calendar date picker
<input type=”month”> for month
<input type=”week”> for week
<input type=”time”> for timestamp
<input type=”datetime”> for precise, absolute date+time stamp
<input type=”datetime-local”> for local dates and time
<input type=”number”> for spinbox
<input type=”range”> for slider
<input type=”color”> for color picker
<input type=”tel”> for telephone number
<input type=”url”> for web address
<input type=”email”> for email address


Difference between MySql drop table, truncate table, delete from table commands

DROP TABLE tablename;

DROP command is used for deleting the table and its structure from the data base.Use this command when you don’t need that table any more.


Other Spec:

1. Removes a table from the database.Table structures, indexes, privileges, constraints will also be removed.
2. Cannot be rolled back.
3. No Triggers can be fired.


DELETE FROM tablename;

DELETE command is used for deleting the records from the table, and it removing the table space which is allocated by the database, and returns number of rows deleted.Delete allows you to use a WHERE clause so you can delete specific records according to your requirement.


Other Spec:

1. Can be rolled back, as during DELETE operation, all the data get copied into Rollback Table space first, and then delete operation perform.
2. Does not reset identity of the table.
3. Triggers can be fired.



TRUNCATE operations drop and re-create the table, which is much faster than deleting rows one by one, particularly for large tables.
After this, the table is empty, and auto-incrementing keys are reset to 1.It faster than DELETE because delete scan the table to generate a count of rows that were affected.


Other Spec:

1. Removes all rows from a table, but the table structures and its columns, constraints, indexes remains.
2. Cannot be rolled back.
3. Resets the identity of the table.
4. Cannot use TRUNCATE on a table referenced by a FOREIGN KEY constraint.
5. No Triggers can be fired.
6. Cannot use WHERE conditions.


Create Custom Google +1 Button

Social network by internet giant is “Google+” getting popular exponentially and of course they already have a huge customer database and all they have to do is to promote this new product among them.However people know the fact that Google+ is very special kind of social network with very unique features.


In parallel to Google+ they introduced +1 buttons for web masters.However the design of +1 button is non alterable and doesn’t go with most of the common web templates.If you already have +1 button, when you take your mouse over, it will pop up sharing window which is user unfriendly šŸ™


You can also create Google +1 and share button with your own icon by follow some very simple steps:


First step you need a suitable icon/image for Google+ share button.Find it and edit in the way you want.

Then you have to prepare Google+ share URL. URL (Replace ‘YOUR URL’ with actual page URL)


If you are using wordpress blog, you can use below code.<?php the_permalink(); ?>


If you want a pop up window use the below code.

[php]<a href="javascript:void(0);" onclick="‘<span style="color: #ff0000;"><?php</span> the_permalink(); <span style="color: #ff0000;">?></span>’,’popupwindow’,’scrollbars=yes,width=800,height=400′);popUp.focus();return false">Share on Gogole+</a>[/php]

You can also update the linkĀ  with an image icon with below code.

[php]<a href="<?php the_permalink(); ?>"><img src="your-custom-google-plus-icon/path/gplus.jpg" alt="Google+" title="Google+" /></a>[/php]

PHP Recursion and recursive routines

Recursion and recursive routines is a bit more complicated, it can be defined as a regular function that calls itself.


Learning when and how to apply recursion is probably a lot more difficult than just learning what recursion is? and being able to explain recursion effectively in an interview situation is even more difficult one šŸ™‚


For beginners defining recursion is easy ā€“ any function that calls itself is a recursive function. Isn’t it?


But do you know what is recursion used for?


Recursion is best used for the case where a large task can be broken down into a repetitive “sub-task”. Because a recursive routine calls itself to perform those sub-tasks.


Factorial is the best example to understand the recursive case.

function factorial($x)
if($x &gt; 1){
/* recursive case */
return factorial($x-1) * $x;
else /* base case */
return 1;


Where $x is the number whose factorial we want to find and that is what recursion is all about ā€“ finding repetitive patterns, and breaking a problem down into repetitive sub-tasks.


Equal and Identical comparison operators in PHP / == (equal) or === (identical)

Equal and Identical comparison operators in PHP


When comparing values in PHP for equality you can use either the == (equal)Ā operator or the === (identical)Ā operator. Do you know, what is the difference?


Very simple the == operator just checks to see if the left and right values are equal. But, the === operator (note the extra ‘=’) actually checks to see if the left and right values are equal, and also checks to see if they are of the same variable type (like whether they are bothĀ boolean, ints, etc.).


Example of when you need to use the === operator in PHP




//Bad code
if ( strpos( $yourString, ‘searchMe’ ) == false ) {
// do your logic here

//Good code
if ( strpos( $ yourString, ‘searchMe’ ) === false ) {
// do your logic here




You can now see that ‘==’ check values only but ‘===’ check values as well as the data type of vales also.


The operator == casts between two different types if they are different, while the === operator performs a ‘typesafe comparison’. That means that it will only return true if both operands have the same type and the same value.


Hope it will make sense?



Difference between !=(not equal to) and !==(not double equal to) in php

Hopefully, you can think that !== operator as being more ‘strict’ than the != operator.


This is because the !== operator will say that the two operands being compared are not equal only if the type of the two operands are the same, but their values are not equal.


This is desirableĀ behaviourĀ because the strpos function can return a 0 if the string being searched contains the substring as the very first element.The 0 would represent the 0th index of the larger string, meaning the first position in that string. This means that the check being performed will be to see if 0 is not equal to false. But the problem is that 0 is also considered as the integer equivalent of the boolean ‘false’ in PHP, which means that the statement ‘0 != false’ will be considered false, because 0 is equal to false in PHP.


But, if we run ‘0 !== false’ instead, then that statement will be considered to be true, because it just adds the additional check to see if 0 and false are of the same type. Since 0 is an integer and false is a boolean, clearly they are not equal so comparing the 0 and false for inequality returns true unlike the ‘0 != false’ check, which returns false.



Let’s take an example


$string = ‘ScriptArticle is helpful’.

if (strpos($string,’ScriptArticle’) != false) {
echo ‘I found ScriptArticle!’;


As the ‘ScriptArticle’ should found on the string and it should print ‘I found ScriptArticle!’, but as it is on 0th index so it considered as false and it will not print anything at all.


But if you use ‘!==’Ā insteadĀ of ‘!=’ then it will compared the types also and 0 is integer and false is boolean so the condition will satisfy and print the statement inside the if.