PHP syntax Basics

Source: Internet
Author: User
I. Basic Syntax of PHP5.4 1. PHP comments and syntax Identifiers (1). Single line comments come from C # C language comments (2) multi-line comments ** the variables and variable data type variables from C language comments 2 and PHP5.4 start with a dollar sign "$" and "$" is an identifier. The ID string contains only letters and numbers.

I. Basic Syntax of PHP5.4 1. PHP comments and syntax Identifiers (1). Single line comments // comments from C # comments from C language (2), multi-line comments/**/C-language comments 2. PHP5.4 variables and variable data type variables start with a dollar sign "$," $ is an identifier. The ID string contains only letters and numbers.

Zookeeper

I. Basic syntax format of PHP5.4



 
 1. PHP comments and syntax identifiers 
 

(1) single line comment // comments from C ++ # comments from C Language

(2) multi-line comments/**/comments from C Language


2. Data Types of PHP5.4 variables and variables

A variable starts with a dollar sign "$" and is an identifier after "$. A string can contain letters, numbers, and underscores and cannot start with a number.

    
Variable naming method

(1) Direct Connection Between words

$ Titlekeyword

(2) Words are connected by underscores.

$ Title_keyword

(3) uppercase letters (hump) between words)

$ TitleKeyword

PHP data types are as follows:

(1) String: Content in single quotation marks (simple quotation marks) or double quotation marks (function quotation marks)

(2) integer:-2 ^ 32 <n <2 ^ 32-1

(3) floating point character (float or double) 1.8E + 308 (1.8x10 ^ 308)

(4) boolean (boolean) true or false

(5) Array)

(6) Object)

  UserName ;}$ p = new Person (); $ p-> getMsg ();?>

(7) resource type (Resouce) system data resources

A resource is a special data type and cannot directly obtain variables. It needs to be accessed through special functions:

Database Access must be implemented through the Mysql function library, Mysqli function library, or PDO function library.

File Access must be implemented through the FileSystem function library.

Directory operations must be performed through the Directory function library.

Image operations must be implemented through the GD function library.

(8) NULL (NULL)


What is the difference between Single and Double quotation marks for string reference?

The difference between the two is that variables contained in double quotes are automatically replaced with actual values, while variables contained in single quotes are output according to common strings.

Iii. PHP5.4 system constants and custom Constants

Constants cannot change data during program execution, and their scopes are global. The constant name is similar to the variable name, but it does not contain the "$" symbol. A valid constant starts with a letter or underscore. Generally, constants in PHP are uppercase letters and can be divided into system constants and custom constants.

Example of system constants:

_ FILE _ default constant, indicating the PHP program FILE name and Path

_ LINE _ default constant, indicating the number of lines in the PHP Program

_ CLASS Name

The define () function is used in PHP to define a constant. The syntax format is:

Bool define (string $ name, mixed $ value [, bool case _ $ insensitive])

Name: constant name

Value: Constant value

Insensitive: Specifies whether the constant name is case sensitive. If it is set to true, It is case insensitive. If it is set to false, it is case sensitive. The default value is false.

Define ("COLOR", "red"); // defines a constant COLOR with the value of red echo COLOR ."
"; // Outputs the COLOR value of the constant.


Iv. Variable Expansion



Variable


$ A = "B" $ a = "123" // variable echo $ B;
Output result: 123

Double quotation marks are used to output variables in strings.

$ A = 50; // echo 'I have $ a yuan renminbi "; single quotes echo" I have $ a yuan renminbi ";

In double quotation marks, more Conversion characters can be executed, such as \ n \ t \ r.

Determine Data Type

$a="-5";  //$a=-5;  var_dump($a);  



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.