Results 1 to 6 of 6

Thread: What are the Basic Syntax used in PHP?

  1. #1
    Join Date
    May 2009
    Posts
    637

    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.!!

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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
    }
    ?>

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    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.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    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' ?>

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    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.!!

Similar Threads

  1. How To Check SQL Syntax in Server
    By DARIELLE in forum Software Development
    Replies: 6
    Last Post: 27-03-2012, 11:37 AM
  2. MS project formula's syntax and example
    By Amichait in forum Microsoft Project
    Replies: 1
    Last Post: 11-11-2011, 04:40 PM
  3. Problem with header() + syntax
    By Leiff in forum Software Development
    Replies: 4
    Last Post: 22-01-2010, 11:07 PM
  4. What is a syntax error?
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 09:53 AM
  5. Syntax for SQL query in JSP.
    By elldeegee in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 10:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,739,913.85589 seconds with 16 queries