PHP basic syntax _ PHP Tutorial

Source: Internet
Author: User
PHP basic syntax. PHP basic syntax open notepad, write the following program, save as hello. php: htmlheadtitlePHP test titleheadbody? Php $ lang_namePHP5br; echo welcome to use. $ lang_name; basic PHP syntax

Open Notepad, write the following program, and save it as hello. php:

  

  

  PHP testing

  

  

  

$ Lang_name = "PHP5
";

Echo "welcome". $ lang_name;

// Print "use $ lang_name to print the text here
";

Printf ("This is a display style similar to the C language
");

/*

PHP multi-line comment

*/

?>

This is a super .

  

  

Based on the above example, let's take a look at the basic PHP syntax:

1. PHP embedded HTML method

Take" "End, with PHP code in the middle.

To Starting The PHP operation code is in the middle.

Take" "End, the middle is the PHP operation code. Variable embedding uses the <% echo variable %> format.

Start with "<%" and end with "%>". The PHP operation code is in the middle. Variable embedding using <% echo variable %>

Note: We recommend that you use the first method. methods 3rd and 4 are not supported.

2. the file package contains two methods: require and include.

The require function is usually placed before the PHP program. Before executing the program, read the file specified by require. This method can be used to introduce the required files.

The include function is generally placed in the processing part of the process control. when the PHP program reads the include file, it will read the introduced file. For example:

Include ("mysql. db. class. php ");

Require ("mysql. db. class. php ");

If a syntax error exists in the file contained by require or does not exist, the system will prompt a Warning of Fatal error and immediately terminate the program running. the include command only displays a Warning error, then execute the statement after the script.

3. PHP variables

PHP variables start with $ and use names as the distinction between variables. Naming rules are similar to those in C, so we will not repeat them here.

Initialization of common variables: $ var_name = value. For example, $ num = 123; $ str = "phpbook"; $ bool = false; $ a = 1.2e3; $ var = null;

Array variable initialization

$ Array name [key name] = value; for example: $ animals ['A'] = 'tiger ',...; $ Array name = array (key name 1 => value1, key name 2 => value2 ,...); $ Birds = array ('b1 '=> 'owl', 'B2' => 'magpie ',...);

$ Array name [] = value; for example: $ mon [] = 'July 6'; $ mon [] = 'July 6'; $ array name = array (value1, value2, ...); For example: $ arr = array ('A', 'B', 'C ');

Notepad open notepad, write the following program, and save it as hello. php: html head titlePHP test/title/head body? Php $ lang_name = PHP5br/; echo welcome to use. $ lang_name ;...

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.