What are the Basic Syntax used in PHP?
Hi friends,
I am new for the PHP programming language. Before that I have done C, C++ and Core Java as programming language. I am very new to PHP so I am not having any idea about it. Thought that you guys would be interested in helping me.!! Please provide me some basic tags that are used in PHP. Also I want to ask what are the Basic Syntax used in PHP? Hope that yuo got the point that I am trying to ask.!! Thanks in Advance.!! :notworthy
Re: What are the Basic Syntax used in PHP?
Before going directly for the syntax, you should know the basic concepts of that. The code that you write in PHP is executed on the server whereas the plain HTML result is sent to the browser. The block that you use for the PHP should always start with the <?php and that coding should end with ?>. You can place a scripting block anywhere in the document. The main reason for including the start and end block is that when parsing a file in PHP, parser looks for an opening and closing tags, which tell PHP to start and stop interpreting the code between them.
Re: What are the Basic Syntax used in PHP?
While doing the coding most of the time you will see PHP embedded in HTML documents. The following example will explain you the same :
PHP Code:
<p>You will have to ignore this.</p>
<?php echo 'While this will be parsing.'; ?>
<p>You will have to ignore this as well.</p>
You can also use more advanced structures, like I have done below in the following example :
PHP Code:
<?php
if ($expression) {
?>
<strong>This is correct.</strong>
<?php
} else {
?>
<strong>This is incorrect.</strong>
<?php
}
?>
Re: What are the Basic Syntax used in PHP?
I think that you should go little deep now. So I have tried you to explain more about the opening and closing tags. You can use four different pairs of opening and closing tags in PHP programming language. Out of them two are, <?php ?> and <script language="php"> </script>, which are always available. Whereas the other two are short tags and ASP style tags. These tags, you can turn on and off from the php.ini configuration file. Even these are the convenient tags, I would like to recommend you not to use these tags, since they are less portable.
Re: What are the Basic Syntax used in PHP?
Since you know the C programming language, as in that similarly PHP requires instructions to be terminated with a semicolon at the end of each statement. Also you will not need to have a semicolon terminating the last line of a PHP block because the PHP code automatically implies a semicolon after the closing tag of a block. You can check this in the example of the coding given below :
PHP Code:
<?php
echo 'This is a demo';
?>
<?php echo 'This is a demo' ?>
Re: What are the Basic Syntax used in PHP?
PHP supports 'C', 'C++' style comments. The example demonstrates the same :
PHP Code:
<?php
echo 'This is an example'; // This is a one-line c++ style comment
/* This is a multi line comment
yet another line of comment */
echo 'This is yet another example';
echo 'One Final Example'; # This is a one-line shell-style comment
?>
The one-line comment styles only comment to the end of the line or the current block of PHP code, whichever comes first. Hope that you got the point that I was trying to explain.!!:thumbup1: