Tag Archives: PHP
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:
syntax to write the php block.
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:
echo “both variables are equal”;
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
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.
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!
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:
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.
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!
We recommend that the reader should go through these tutorials first before PHP tutorial.
PHP stands for Hypertext Preprocessor. PHP can be used in three ways: Server side Scripting, Command Line scripting and Client-side GUI (Graphic User Interface) application. There are many databases which are supported by PHP e.g. MySQL, Solid, Informix , Sybase etc.). PHP is a free to download and use. Also, it is and open source software. PHP runs on various platforms like Windows, Unix and Linux etc. It runs efficiently on server side and is easy to learn. Following is the brief introduction of the ways in which PHP is used:
Server Side Scripting:
PHP is a server side scripting programming language like ASP. PHP is basically designed and best suited to create web content. PHP parser and a web server is used to generate the HTML. The web server is used to send the coded documents. PHP can also be used to generate the XHTML documents, graphics, animations, pdf files, etc.
Command Line Scripting:
The command line can be used to run PHP scripts like Perl, Unix Shell, or awk. These command line scripts can be used for various administration tasks of a system like log parsing or backup.
Client-Side GUI Application:
The cross platform GUI applications can be written by using PHP-GTK.
PHP files are capable of containing text, HTML, scripts and various tags etc. The extension of any PHP file is “.php”, “.php3” and “.phtml”. These files return to the internet browser as a plain HTML.
PHP and MySQL:
The database server is known as MySQL. It supports standard SQL. It is available freely to download and use. It is usually used for both small and large applications. It can compile various platforms.
If you need to develop a cross platform application i.e. develop it on Windows and serve on Linux then you can use PHP and MySQL together.