You cannot view the PHP source code Select "View Source file" in the browser-you will only see the output p hp file, which is pure H TML. This is because the script executes the results on the server before it is sent back to the browser.
-------------------------------------------------- ------------------------------
Basic PHP syntax
A PHP script block always starts with "? PHP and purpose? ” 。 A PHP script block can also be placed anywhere in the file.
The support of shorthand on the server, you can enable the startup script block "? and end it? “ 。
However, for maximum compatibility, we recommend that you use a standard format "(<? PHP), rather than in shorthand form.
“ ? PHP's? ”
PHP files typically contain HTML tags, like HTML files, and some PHP scripting code.
Below, we have an example of a simple PHP script to send the text of the "Hello World" browser:
<body> "? The PHP
echo "Hello World";
? "/Weight"
"/html"
Each line of code must be in PHP with a semicolon. A semicolon is a separator that is used to differentiate the instruction set from another.
There are two basic report output text in PHP: Echo and print. In the example above, we used the Echo declaration, the output of the text "Hello World."
Note: The file must be available. PHP extensions. In the archives. HTML file name, PHP code will not be executed.
-------------------------------------------------- ------------------------------
Comments in PHP
In PHP, we use//make a single line of comments or/* and */make a lot of comment blocks.
<?php
This is a comment
/* This are
a comment block
* *
?>
</body>
Variables are used to store values, such as numbers, strings, or functions, so that they can be used for many times as a script.
-------------------------------------------------- ------------------------------
Variables in PHP
Variables are used to store values, such as text strings, numbers, or arrays.
When a variable is set that can be used over and over again in your script
All the variables in PHP begin as symbols of the symbol.
The correct way to set a variable in PHP:
$ var_name = value;
New PHP programmers often forget the variables that start with a flag. In this case, it will not work.
Let's try to build a variable with a string, and a variable with some:
“ ? The PHP
$ text = "World Hello!" ” ;
$ quantity = 16;
? “
-------------------------------------------------- ------------------------------
PHP is a loosely-spoken language
Variables in PHP do not need to be announced before the establishment.
In the example above, you see, you don't have to tell PHP about the variables of the data type.
PHP automatically converts variables to the correct data type, depending on how they are determined.
In a strongly typed programming language, you want to declare (define) the type and name of the variable in use of it.
Variables in PHP are automatically used when declaring them.
-------------------------------------------------- ------------------------------
Variable naming rules
A variable name must begin with a letter or underscore "_"
The name of a variable can only contain alphanumeric characters and underscores (Arizona, State, 0-9, and _)
The name of a variable should not contain spaces. If the name of a variable is more than one word, the separation should be emphasized ($ my_string), or with capital ($ myString)