Open Notepad, write the following program, Save as hello.php:
<title>php Test </title>
<body>
<?php
$lang _name= "php5<br/>";
echo "Welcome to use". $lang _name;
Print "Here uses $lang_name printing text <br>";
printf ("This is a display style similar to C language <br>");
/*
Multiple-line comments for PHP
*/
?>
</body>
In combination with these small examples, understand the basic syntax of PHP:
1, PHP embedded HTML method
Start with "<?php" and End With "?>", with PHP code in the middle.
With the <SC ript language= "PHP" > The beginning, to </SC ript> end, the middle for the PHP operation code.
With the ";?" Beginning with "?>", the middle is the PHP operation code. Variable embedding uses the <% echo variable%> format.
Start with "<%" and End With "%>", with PHP operating code in the middle. Variable embedding using <% echo variable%>
Note: The first method is recommended, and 3rd, 4 methods are not supported.
2, the file contains require and include two ways
The Require function is usually placed in front of the PHP program. Before executing the program, read the file introduced by require. Part of the function that is common to the system, you can use this method to introduce the required files.
The include function is typically placed in the processing section of the process control, and the PHP program reads the included file before it is read into the imported file. For example:
Include ("mysql.db.class.php");
Require ("mysql.db.class.php");
The file contained in require is prompted to warn fatal error if there is a syntax error or nonexistent and terminates the program immediately, and the include simply displays the warning warning error, and then continues executing the statement following the script.
3, PHP variables
PHP variables begin with a $ name as a distinction between variables. Naming rules are similar to the C language, so don't repeat them.
Initialization of general variables: $var _name=value. For example: $num =123; $str = "Phpbook"; $bool =false; $a =1.2e3; $var =null;
Initialization of an array variable
$ array Name [key name]=value, such as: $animals [' A ']= ' Tiger ',...; $ array name =array (key name 1=>value1, key name 2=>value2,...); $birds =array (' B1 ' => ' owl ', ' B2 ' => ' Magpie ',...);
$ array name []=value; such as: $mon []= ' March '; $mon []= ' May]; $ array name =array (value1,value2,...); such as: $arr =array (' A ', ' B ', ' C ');