PHP Basic Syntax Summary

Source: Internet
Author: User
Tags php language php basics
For the basic knowledge of PHP is not firmly the best is to review the basic, but when we look at the PHP Foundation and feel too simple to see, I believe many students have had such experience, then we will take a look at this article PHP Basic Grammar Summary!

1. Code Identification PHP TAG

► Recommended Format <?php?>

► Short label format <??>

※ You need to modify the Php.ini->short_open_tag with the short label, restart Apache

※ The Pure PHP code page, the end tag can be omitted "? > ", it is best to delete at the end of the file. This avoids the accidental addition of spaces or newline characters after the end tag of PHP is output.

2 instruction delimiter ";" Instruction separation

The last line of the ※php code does not write the Terminator ";", and must be entered in the half-width state.

3. How to access

PHP files cannot be opened directly and must be accessed through a domain name or IP address.

The php file name or path, can not contain Chinese!

4. Note Comments

► Single-line Comment

Comment Content (c + + style)

#注释内容 (Unix Shell style)

► Multi-line comments

/* Comment content */(c style)

* Do not use comments to wrap comments

※ Comments can be temporarily disable code

※ The single-line comment only comments to the end of the line or the current PHP code block, which means that in//...? > or # ...? The HTML code after > will be displayed, such as:


5. Case Sensitity

►php variables are case-sensitive;

►php language keywords, functions, custom classes and functions are not partitioned;

6. Blank whitespace

A character that is invisible, such as a space, tab, line break

Whitespace between PHP statements is ignored by the PHP engine.

7. Text literals

Text refers to the data that can be written directly in the program, such as: 2018, 1.3, True, ' Hello may '

8. Identifier Identifier

Identifiers are used to name variables, constants, functions, and classes, and the first character must be either an ASCII letter (uppercase or lowercase), an underscore, or an ASCII character set between 127 and No. 255, and the second character can use a number and the other above characters.

ASCII Character Set 0-127

9. Language keyword Keywords

can also be called reserved word (Reserved words), is the implementation of the language core functions and pre-set, regardless of the case, variables, methods and other names cannot be the same name. Common: Echo, const, if, print, return, new

In addition, PHP built-in functions cannot duplicate a custom function.

10. Single and double quotes

When a variable is included in a single quotation mark , the variable is output as a string.

When a variable is enclosed in double quotes , the variable is parsed and the value is output;

* Only single quotes and backslashes are handled in a single quote string.

Single quote double quotation mark

$STR = ' Jax said: ' 2017, thanks for having you '

Double quotation marks in single quotation marks

$str = "' Wait for me to rise and repay you '";

It can also be single-embedded, double-nested

11. Escaping

Some characters are "specially treated" by the PHP parsing engine, so write them out to escape, escape the character backslash "\", and add to the characters that need to be escaped, such as:

echo "\" On the hall, under the kitchen, knock out code, find out the exception \ ""

The other escape characters are the following table:

A regular expression is a custom rule that queries retrieve a specified string, saying that the regular expression is the basis, but the regular expression is not so easy to understand.

Review the foundation of consolidation:

PHP Basic Knowledge Note sharing

PHP Basic Knowledge Summary (Beginner's Essentials)

PHP Basics: Custom Function usage examples

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.