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