1. Write a comment
Comment in HTML file
<! -- Comment goes here. -->
HTML annotations can be seen in the source file, but are not displayed on the rendered page.
PHP comments are not sent to the web browser, even if you view the Web source file.
PHP annotations support three types:
# This is comment.
// This is also comment.
Both of these annotations make PHP ignore all the warmth from the end to the end of the line. Therefore, it is a single line comment. They can also be used in PHPCodeAdd comments to the row.
The third option can be distributed across multiple rows.
/* This is a longer commentthat spans two lines .*/
Add a comment to the script
<? PHP # Created August 27,200 7 # Created by Larry E. ullman # This script does nothing much. echo '<p> This is a line of text. <br/> This is another line of text. </P> ';/* echo' this line will not be executed. '; */echo "<p> now I'm done. </P> "; // end of PHP code.?>
Each script should contain one of the first comments as an introductory module, which lists the creation date, modification date, creator, contact information of the Creator, and the purpose of the script. Some people think that shell-style annotations (#) are more eye-catching in scripts, so such annotations are the best.
2. Variables
A variable is a container used to temporarily store values. These values can make numbers, text, or much more complex data. PHP has 8 medium variables. There are four scalar (single value) types: Boolean (true or false), integer, floating point, and string, and two non-standard (multi-value) types-array and object, and resources (you will see it when interacting with the database) and null (it is a special type that does not have any value ).
Regardless of the type of variable created, all variables in PHP must comply with the following syntax rules:
- The variable name, also known as the identifier, must start with $, for example, $ name.
- A variable name can contain a combination of letters, numbers, and underscores.
- The first character after the dollar sign must be a letter or underline, not a number.
- Variable names in PHP are case-sensitive. This is a very important rule.
The following are some predefined variables. Note that you can use the = Operator to print variables without quotation marks.
Print $ some_var; // or print the variable print "Hello, $ name" in double quotes; // The variable print 'hello, $ name' // won' t work!
// Create a shorthand version of the variable names: $ file =$ _ server ['script _ filename']; // store the complete path and name of the script to be run $ user = $ _ server ['HTTP _ user_agent ']; // The browser and operating system of the user who stores the Access Script $ server =$ _ server ['server _ soft']; // stores the applications on the server running PHPProgram(Such as Apache and nginx) // print the name of this script: Echo "<p> you are running the file: <br/> <B> $ file </B>. </P> \ n "; // print the user's information: Echo" <p> you are viewing this page using: <br/> <B> $ user </B> </P> \ n "; // print the server's information: Echo" <p> This server is running: <br/> <B> $ server </B>. </P> \ n ";
A string is a string of characters enclosed in quotation marks: letters, numbers, spaces, punctuation marks, and so on. To create a string variable, you can assign a valid variable a string value.
$ First_name = 'tobias'; $ today = 'dec 7 2012 ';
When creating a string, you can use single quotation marks or double quotation marks to encapsulate characters, just as you did when printing text. Quotation marks of the same type must be used at the beginning and end of a character. If the same quotation marks appear in the string, escape them. The echo () or print () function can be used to print characters.