Php syntax checker

Admin   PHP   352  2021-03-04 08:26:17

When you first learn to code, the most important thing you must do regularly is practice writing code continuously to remember syntax in PHP. Because in general programming, if you miss a small syntax, even single quotes (') are enough to make your program not run.

Php syntax checker

Therefore, in this article, I will go over some of the basic syntax rules that you need to know when writing PHP code.

EMBED PHP IN THE DOCUMENT

When you need to embed PHP in any file, the PHP code must be in the opening <?php and closing tag ?>. The example below is to include PHP in 

<div class="content">

    <?php

       echo " PHP";

    ?>

</div>

In some cases, if the short data is written in PHP, I can open many PHP tags for easy viewing like this:

<div class="content">

    <h1 class="title"><?php the_title(); ?></h1>

    <?php the_title(); ?></h1>

</div>

In general, PHP cannot write directly into the document, but must be placed in pairs <?php ?>.

THE END OF A PIECE OF CODE

On a PHP snippet, it will be terminated with a semicolon ( ;).

<?php

    $a = array();

    $a[0] = 'Hello';

?>

However, code enclosed in curly braces {} does not need a semicolon.

WRITE COMMENTS IN THE CODE

When writing code, programmers often write comments on the code to take notes or help others read their comments about the code. In PHP there are 2 types of comments are:

  • Single-line comment : Comment on a single line
  • Multi-line comment : Comment on multiple lines

Here is the comment syntax:

<?php

    // You can comment on a single line

 

    /*

    Or comment

    more lines

    different

    */

 

    /*=================================

     * You can write nice comments like this *

     *=================================*/

?>

That means if you comment on one line, you write characters //or in front of the content. As for multi-line comments, you will have the opening character /*and must close with the letter */.

CAPITALIZATION IN PHP

In PHP, all element names such as keyword (if, else, while, echo, ...) are case insensitive. That means you can write anything you like. The following examples are all valid:

<?php

    echo 'Standard, valid';

    Echo 'Still valid';

    eCho 'Still valid';

    ECHO 'Valid note';

?>

 

I recommend that when writing keywords, you should write them all in lower case for easy reading.

But some cases as the declared variable name ( variable ) is that it distinguishes uppercase and lowercase.

And to declare constant ( constant ), you must write HOA.

<?php

    define('NAME', 'BLOGDEV');

?>

Epilogue

In this article, you have become familiar with the basic syntax in PHP. You may find a lot of confusing parts in some of the code examples above, but that's okay because you will understand it after reading a few more articles later. In the following article, I will show you the concept of variables because if you learn basic PHP , the use of variables is a lot.

Source: thachpham.com