PHP Programming Syntax Overview - Learn easily for Beginners
This section will present you an thought of easy basic syntax of PHP Language & very important to create your PHP foundation strong.
Escaping to PHP Language
The PHP Language parsing engine requirements a way to make different PHP Programming syntax from other part in the page. The method for doing so is known as 'escaping to PHP Language'. There are 4 method to do this.
Canonical PHP Programming tags
The most commonly useful PHP tag style
<?php...?>
If you use this technique, you can be positive that your tags will constantly be right interpreted.
Short -open (Standard Generalized Markup Language (SGML)-style) tags
Short or short-open tags look like −
<?...?>
small tags are, as one force expect, the shortest opportunity You must do one of two possessions to allow PHP to identify the tag −
• select the - allow - short-tag design option when you are structure PHP.
• fix the short open tags set in your php.ini file. This selection must be disable to parse XML with PHP because the same syntax is use for XML tag.
ASP-style tags
ASP - style tags imitate the tags used by Active Server Page to outline code block. ASP - style tag like this −
<%...%>
To use ASP - style tag, you will need to be set the configuration selection in your php.ini file.
HTML script tags
HTML script tag like this −
<script language="PHP">...</script>
comment PHP Code.
A comment is the part of a programming that exist only for the individual reader & exposed out previous to display the programming effect. There are two comment format in PHP −
Single - line comments:- They are normally use for small explanation or note related to the locals code. Here are the example of single line comment.
<?
# This is a comment, and
# This is the second line of the comment
// This is a comment too. Each style comments only
print "An example with single line comments";
?>
Multi lines printing:- Here are the example to publish various position in a single print statement −
<?php
# First Example
print <<< END
This use the "here document" syntax to output
various lines with $variable interpolation .
Note
that the here document terminators must appear on a
line with just a semicolon not extra white space !
END;
# Second Example
print "This spans many lines. The new lines will be output as well";
?>
Canonical PHP Programming tags
The most commonly useful PHP tag style
<?php...?>
If you use this technique, you can be positive that your tags will constantly be right interpreted.
Short -open (Standard Generalized Markup Language (SGML)-style) tags
Short or short-open tags look like −
<?...?>
small tags are, as one force expect, the shortest opportunity You must do one of two possessions to allow PHP to identify the tag −
• select the - allow - short-tag design option when you are structure PHP.
• fix the short open tags set in your php.ini file. This selection must be disable to parse XML with PHP because the same syntax is use for XML tag.
ASP-style tags
ASP - style tags imitate the tags used by Active Server Page to outline code block. ASP - style tag like this −
<%...%>
To use ASP - style tag, you will need to be set the configuration selection in your php.ini file.
HTML script tags
HTML script tag like this −
<script language="PHP">...</script>
comment PHP Code.
A comment is the part of a programming that exist only for the individual reader & exposed out previous to display the programming effect. There are two comment format in PHP −
Single - line comments:- They are normally use for small explanation or note related to the locals code. Here are the example of single line comment.
<?
# This is a comment, and
# This is the second line of the comment
// This is a comment too. Each style comments only
print "An example with single line comments";
?>
Multi lines printing:- Here are the example to publish various position in a single print statement −
<?php
# First Example
print <<< END
This use the "here document" syntax to output
various lines with $variable interpolation .
Note
that the here document terminators must appear on a
line with just a semicolon not extra white space !
END;
# Second Example
print "This spans many lines. The new lines will be output as well";
?>
Multi lines comment:- They are normally used to afford artificial cods algorithms & extra details explanation when needed. The multi line style of comment is the same as in php. Here are the pattern of multiline comments.
<?
/* This is a comments with multi line
Author : Binod yadav
Purpose : Multi line Comments Demo
Subject: PHP language
*/
print "An example with multi line comments";
?>
PHP Language is white space insensitive:
Whites pace is the things you type that is normally unseen on the screen, with spaces, tab, & carriage return (end of line character).
PHP white space insensitive means that it almost in no way matter how many white space characters you have in a row . one white space quality is the same as many such as characters.
For example: each of the next PHP statement that assign the sum of 4 + 4 to the variable $four is equal :
This will create the next result :
Braces make blocks
Every though statement can not be mutual like language, you can all times puts a sequences of statement any where a statements can go by enclose them in aset of curly brace ({}).
Here both statement are equivalent:
if (4 == 2 + 2)
print("Good- I have not totally lost mymind<br>");
if (4 == 2 + 2) {
print("Good- I have not totally");
print("lost my mind <br>");
}
Run PHP Scripts from Commands Prompt:
Sure you can run your PHP scripts on your commands prompt . presumptuous you have next contents in hello.php file.
<?php
echo "Hello PHP Program!!!!!";
?>
At present run this scripts as command prompt as follows:
$ php hello.php
It will create the next result :
Hello PHP!!!!
I expect now you have basic knowledge of PHP Syntax..
Variable capitals is 67
Variable Capitals is.
Statements are expressions terminated by semicolons In PHP
A statement in PHP Language is any appearance that is followed by a semi colon (;) . Any series of valid PHP language statement that is en-closed by the PHP tag is a valids PHP programming. Here is a typical statements in PHP , which in this case assign a strings of character to a variables called $greeting-$greetings = "Welcome to PHP language!";
Expression are combination of token Php
The minimum structure block of PHP are the inseparable token, such as number (4.16157), string (.two.), variable ($two), constant (TRUE), & the special word that create the syntax of PHP it self like if , else , while , for & so forth.Braces make blocks
Every though statement can not be mutual like language, you can all times puts a sequences of statement any where a statements can go by enclose them in aset of curly brace ({}).
Here both statement are equivalent:
if (4 == 2 + 2)
print("Good- I have not totally lost mymind<br>");
if (4 == 2 + 2) {
print("Good- I have not totally");
print("lost my mind <br>");
}
Run PHP Scripts from Commands Prompt:
Sure you can run your PHP scripts on your commands prompt . presumptuous you have next contents in hello.php file.
<?php
echo "Hello PHP Program!!!!!";
?>
At present run this scripts as command prompt as follows:
$ php hello.php
It will create the next result :
Hello PHP!!!!
I expect now you have basic knowledge of PHP Syntax..
PHP Programming Syntax Overview - Learn easily for Beginners
Reviewed by Binod Kumar
on
00:04
Rating:
No comments: