HTML Online Tutorial Contents

Following are the posts for HTML online Tutorial. To learn everything about HTML, just read these posts: HTML Online Tutorial HTML TAGS (2) HTML BASICS (3) HTML ELEMENTS (4) HTML ATTRIBUTES (5) More »

XHTML

XHTML stands for Extensible Hypertext Markup Language. It is also known as XML (Extensible Markup Language). It is a markup language. In XHTML, there are no predefined tags. The user defines the More »

HTML SUMMARY

In this tutorial, you learned: HTML Introduction HTML Tags HTML Basics HTML Elements HTML Attributes HTML Paragraphs HTML Headings HTML Formats HTML Image HTML Links HTML Lists HTML Frames HTML Table After More »

HTML TABLES (13)

HTML Tables are used to arrange data in web pages. HTML allows the use of tables by <table>…</table> tags. Each row in HTML table is recognized by <tr>…</tr> tag. In each row More »

HTML FRAMES (12.2)

Nested frames example: For the following example to work, there are two other simple HTML files : “HMTL11e1 frame a.html” and “HMTL11e1 frame b.html”. your browser will divide your screeub half. The More »

 

Tag Archives: PHP semicolon

Learn about the syntax of PHP with examples

Learn about the syntax of PHP with examples

To learn every programming language it is necessary to understand its syntax. For PHP we will start from LEXICAL STRUCTURE which is basically the lowest level of syntax for PHP. Lexical structure defines how we name the variables, the characters we can use or how we can insert comments in the program etc.

PHP is case sensitive and insensitive: The variables which can be defined in PHP are case sensitive. But the names of user defined functions and classes are case in-sensitive in PHP. Moreover the keywords and constructs which are build in PHP are case insensitive as well. An example of keyword is echo:

echo(“My blog is website-school “);

Echo(“My blog is website-school “);

eCho(“My blog is website-school “);

All of the above statements are same.

Since we know that PHP code is executed on server. As a result the plain HTML is sent back to the browser.

PHP Scripting Block:

The php block will always start with .  But if the server supports the shorthand then the php block will start from . The position of PHP block can be anywhere in the document. Since you want your document to provide as much as compatibility as possible so you should use the:

php

?>

syntax to write the php block.

PHP Statements:

The collection of PHP code that does something is known as PHP statement. For you,  easiest example of PHP statement could be variable assignment such as:

$website = 50;

$demon = 2;

you should note that variable is basically a changing value. You can declare a variable name and type once and can change its value at any point in the program and as many time as you want. In the above statement the website is the variable that you will declare in php and assign it a value of 50. You really need to remember that variable name in PHP starts with $ sign! Similarly, the demon variable has been given a value of 2.

$school = “blog”;

If you look at the above statement then you will notice that the variable school does not have numerical value, instead it has been assigned a word “blog” as a value. You need to remember that the words (or group of words i.e. complete sentences as well) are written inside quotation marks while assigning them to a variable.

Similarly, the complicated example of PHP statement can be loop that has multiple checks or exit points such as:

if ($website==$demon)

{

echo “both variables are equal”;

echo “YAHOO”;

}

The above example is a if else loop which will be explained in a loop section in detail. But for now all you need to know is that this loops checks if the value of website and demon are equal. If yes than the output of loop will be a statement:

both variables are equal YAHOO

For now you don’t have to worry about LOOPS. We will get there Learn about the syntax of PHP with examples

Since we are discussing PHP statements, so I want to mention Compound statements. The statements which are enclosed in braces are basically known as Compound statement. Like the echo statements in the above loop are compound statements.

I know that those of you who know nothing about programming are wondering what is the purpose of semicolon? First I want to introduce you to comments in PHP code.

PHP Comments:

The comments about the code can be written after each statement by putting // after the end of every statement. You can either do that or you can put your comments between /* comment*/ to insert a large block of comments in the code.

Now we will move on to semicolon!

PHP Semicolon:

The semicolon in PHP statements is used to separate the single statements. It also act as a separator from one group of statements to another set of statements. The compound statements do not require the semicolon after a closing brace of any loop or conditional test. But in the single compound statement the semicolon is must. For example, if you see this example again:

if ($website==$demon)

{

echo “both variables are equal”;     // semicolon is compulsory here.

echo “YAHOO”;    // semicolon is compulsory here.

}  // semicolon is not required here.

Now I think that you can easily recognize the comments after each statement. If you are writing a PHP code, then you can easily skip the semicolon after the PHP tag because using a semicolon after a PHP tag is optional.

php

if ($website==$demon)

{

echo “hi”;

}

echo “YAHOO”    //semicolon is optional after this tag

?>

But for good programming practice, You need to remember that semicolon are must at the end of every single statement, they are not use at the end of compound statement end brace and they are optional after PHP tag. But you should put them after PHP tag so that you don’t get confused.

To get a mobile app for your business visit www.codescamp.com

Book a free consultation today!