PHP Getting Started learning--php syntax

Source: Internet
Author: User
I. Introduction of PHP
(1) PHP: Chinese name, hyper-text preprocessor, is a common open source scripting language;
(2) Dreamweaver introduction

(3) Four types of delimiters

Standard style: ;
Short Mark Style: ;
By default, the short markup style is not supported, in the PHP configuration file (php.ini) to open the support of the short mark;
In the configuration file, search for "Short_open_tag", modify the parameters to on, restart the Apache server;
ASP style: <%%>;
ASP-style delimiters are not supported by default, and support for ASP tagging is enabled in the configuration file (php.ini);
In the configuration file, search for "asp_tags", modify the parameters to on, restart the Apache server;
Script style:;
PHP support omit the end tag, PHP start delimiter after the end of all the PHP code, you can omit the PHP code;
(4) PHP Implementation principle:
The client sends a request to the server, and if the request is an HTML page, the server sends the HTML page directly to the client to parse the browser, and if the PHP page is requested, the server runs the PHP page and generates a standard HTML page that sends the generated HTML code to the client ;
The client parses the HTML code, but does not run the PHP code;
The server side does not parse the HTML, but runs the PHP code;
II. Features of PHP syntax
(1) The PHP statement ends with a semicolon;
(2) PHP keywords are not case-sensitive, variable names are case-sensitive;
Third, variable
(1) Naming rules for variables:
PHP must start with $, and $ is not part of the variable, it simply means that the PHP variable name starts from here;
In addition to $, letters, underscores, followed by letters, numbers, underscores;
(2) Assignment of variables: use "=" to assign values;
(3) Destroy variable: unset ($x);
Unset () destroys the variable name, and the value is destroyed by the PHP garbage collection mechanism;
(4) Variable variable
$a = "Hoe wo Day Copse";
$b = "a";
echo $ $b;
Output: Hoe wo day copse;
$b Save the variable name A, so the $ $b is $ A and the last $ A value is output;
(5) Constants
When a value changes within the execution period of the script, the value can be declared as a constant, using the define () keyword;
A constant name cannot have a $ start;
Define ("name", "Li Bai");
Define ("Constant name", "value", whether case-sensitive ture or false);
Ture is case insensitive, false for case sensitivity;
By default, the name of the constant is case-sensitive;
Constants cannot be defined repeatedly, and when defining constants, the current constants are defined, and the defined () function is judged;
Iv. data types of variables
(1) Scalar type
Integer, floating-point number (float, double is the same), Boolean (TURE, FALSE), String (single and double quotes);
(2) String type
The single-quote string does not replace the variable ($name), and the double-quote string substitution variable ($name) is the value of the variable;
Because single-quote strings do not require operations, single-quote string execution is more efficient;
If the variable is in the front or middle of the string, it needs to be enclosed in curly braces {};
The left Curly brace {and $ must be next to each other, the middle cannot appear space;
The left curly brace {and the position can be interchanged;
(3) Type of conformance
Array (arrays), object (objects);
Array: $students = Array (' Tom ', ' Jack ', ' ketty ');
Indexed array: Sit down by the position of the element, the default starting from 0, you can change the starting subscript, $students [0], $students [1];
$emp =array (' name ' = ' Zhang Jie ', ' age ' = ' + ', ' sex ' = ' boy ');
Keyword index: Gets the element through the element's keyword, $emp [' name '], $emp [' sex '];
Specify array subscript: $index = Array (1=> ' a ', 3=> ' B ', 5=> ' C ');
(4) Special type
Resource (Resource): PHP external data is called the resource type;
NULL (no type): no data;
Five, output statements
(1) Echo: can only output numbers, strings;
For Boolean type, ture can only output 1,false only output null;
Compared with print, can output more than one parameter at a time, the output does not return the value of success;
(2) Var_dump (): If the output variable, the value of the variable and the type of the variable;
If the output is an array, including the key, value, value data type;
(3) Print_r (): Used to output an array, the output includes the array's key and value, not including the data type;
(4) Print: Similar to echo statement, only one parameter can be output at a time;
The output will return 1, and the failure will return 0;
Vi. notes
(1) Single-line Comment://and #;
(2) Multi-line Comment:/* */;
Seven, operator
(1) Arithmetic operators:
The plus sign (+) can be used to add numbers in JavaScript or to concatenate strings;
In PHP, the plus sign (+) can only do numeric operations;
(2) Comparison operators:
= = = (congruent): Comparison value and data type;
!== (not congruent): Comparison values and data types, are not equal when established;
(3) Logical operators:&&, | |,!;
(4) String connector:
In PHP, the string connector is a dot (.);
Eight, Judgment statement
(1) Single branch:
(2) Dual branch:
(3) Multi-branch:
(4) Multi-channel selection:
Nine, function
(1) Predefined functions: PHP system functions;
(2) Custom Function: function function name (parameter) {}, functions are called through function name;
(3) Return: Terminates the execution of the function, the function returns the corresponding data;
X. Classification of arrays
(1) Classification by key: indexed array and associative array;
(2) Structural classification: one-dimensional arrays and multidimensional arrays;

The above introduces the PHP introductory learning--php Grammar, including the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.