The basic syntax of PHP

Source: Internet
Author: User
Tags php code require

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 ');

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.