"PHP Learning" PHP syntax

Source: Internet
Author: User

The PHP script executes on the server and then sends back the pure HTML results to the browser. Basic PHP syntax

The PHP script can be placed anywhere in the document.

The PHP script begins with <?php and ends with ?> :

<? PHP // here is the PHP code ?>

The default file name extension for PHP files is ". php".

PHP files usually contain HTML tags and some php script code.

The following example is a simple PHP file that contains a PHP script that uses the built-in PHP function "echo" to output text "Hello world!" on a Web page: an instance

<! DOCTYPE html>PHP Echo "Hello world!" ;? >  </body>

Running an instance

Note: The PHP statement ends with a semicolon (;). The close tag of a PHP block also automatically indicates a semicolon (so you don't have to use a semicolon in the last line of the PHP block). Comments in PHP

Comments in the PHP code are not read and executed as programs. Its only function is for code editors to read.

Comments are used to:

    • Make others understand what you're doing-comments can let other programmers know what you're doing at each step (if you work for a team)
    • Remind yourself of what you've done-most programmers have gone through a year or two to rework a project and then have to rethink what they've done. Comments can record the way you think when you write code.
PHP supports three types of annotations: instance
<! DOCTYPE html> PHP//  This is a single line comment #  This is also a single line comment / * This is a multiline comment block it spans multiple lines * / echo "Hello world!" ;? >  </body>

Run instance PHP case sensitive

In PHP, all user-defined functions, classes, and keywords (such as if, else, Echo, and so on) are not case sensitive.

In the example below, all of these three-day echo statements are valid (equivalent): instance

<! DOCTYPE html>PHP ECHO "Hello world!<br>"; Echo "Hello world!<br>"; EcHo "Hello world!<br>";? >  </body>

Running an instance

In PHP, however, all variables are case-sensitive.

In the following example, only the first statement shows the value of the $color variable (because $color, $COLOR, and $coLOR are treated as three different variables): instance

<! DOCTYPE html>PHP $color= "Red"; Echo $color . "<br>"; Echo $COLOR . "<br>"; Echo $coLOR . "<br>";? >  </body>
Running an instance

"PHP Learning" PHP syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.