PHP basic Syntax Summary, PHP basic syntax
What can PHP do?
What can PHP do? I think it is very strong, as long as I can think of, it can do, but my technical ability is not ╮ (╯﹏╰) ╭. OK, a picture, basic understanding (ps:php function is not limited to this (^_^))
The image is a little blurry, make up, (≧▽≦)/
Second, PHP language tag
1. End and start tag
1.1 <?php//code: XML style, is the standard style of PHP, recommended to use.
1.2: Long style markers, not commonly used. If your miracle editor doesn't support other PHP tags, use it.
1.3 <? Code: Short style, followed by SGML processing. You need to open the directive Short_open_tag in php.ini, or add –enable-short-tags when PHP is compiled. If you want your program to be good transplant, discard this style, it is less than 1.1 PHP.
2. Location
What do you say? Anyway, you can place the PHP language anywhere in the HTML file with the suffix named. php. Note that the HTML file ends in. php.
<?php echo="" 'bgcolor="#ccc" '?="">Copy the Code code as follows:
1:
2:
3:
4:
5:<?php echo "PHP language Tag"?>
6:
7:
8: >
9:
Ten: <?php
11:if ($exp) {
:?>
13:
14:
The condition is true to do the
: <?php
:}else{
:?>
18:
The condition is false to do the
: <?php
20:}
£?>
22:
23:
3. Comments
3.1 Single-line comment://or # Multiline Comment:/* Description */
3.2 Multiline comments cannot be nested, but they can contain single-line comments, and single-line comments can contain multiple lines of comments. That's what it looks like.
Copy the Code code as follows:
1: <?php
2://echo "Test";/* contains multiline comment in single line */
3:/*echo ' Test '; The multiline comment character contains a single-line comment */
4:?>
Third, variable
1, the use of variables
Copy the Code code as follows:
1: <?php
2: $a = 1; Declares a variable a
3: $b = "PHP"; Declare a variable b
4: $8d = 2; Illegal variable name, can only start with a letter or underscore and does not contain spaces
5:
6: $i site is = "PHP"; Valid variable name, can be used in Chinese
7:/*
8: * The following three function call methods are equivalent
9: * Keywords and built-in functions and user-defined class names, function names are case-insensitive
10: */
11:phpinfo ();
12:phpinfo ();
13:phpinfo ();
14:
15:
16:/*
17: * The following three variables are not the same
18: * Variable name is case-sensitive drop
19: */
: $name = "PHP1";
: $Name = "PhP2";
: $NAME = "PhP3";
23:
24://variable variable: Variable name can be set dynamically
: $hi = "Hello";
: $ $hi = "World";
27://Output Hello World below
28:echo "$hi $hello";
29:echo "$hi ${$hi}";
30:
31://Variable Assignment
+: $foo = "B"//Pass Value Assignment
: $bar = & $foo//reference assignment
: $bar = "LZ";
35:echo "$foo"; Output LZ
*: $CDE = $foo; Transfer value Assignment
Panax Notoginseng: $cde = "E";
38:echo "$foo"; Output LZ
:?>
2. Types of variables
Iv. Constants
1. Definition and use
Copy the Code code as follows:
1: <?php
2:/*
3: *boolean define (String name,mixed value[,bool case_insensitive)
4: *name: constant name; value: constant value; Third is an optional Boolean value, default is False (case insensitive)
5: */
6:define ("FLO", 1000);
7:echo FLO; Output 1000
8:
9://Use the Define function to verify that the Flo constant exists, and that the output constant value exists
10:if (define ("FLO"))
11: {
12:echo FLO;
13:}
:?>
2. Constants and variables
The scope of the 2.1 constant is global, and the constants can be declared and accessed anywhere else in the script.
2.2 Constants are not preceded by $, and constants cannot be defined by an assignment statement.
2.3 Constants, once defined, cannot be redefined or undefined until the end of the script run is automatically freed.
2.4 The value of a constant can only be a scalar (one of the types in boolean,integer,float,string)
3. Predefined constants of the system
4. Common Magic Constants
PHP Basic Syntax issues
The double quotation marks are used for the output string. For example: echo "Data insertion failed, error message:
";
and "INSERT into TestTable VALUES ('". $xm. "',". $nl. ")"; INSERT into testtable values is a string that means inserting into the database, two "" is a group that will. $xm. Separate, (. $xm.) The $XM is a variable that uses echo when a variable is displayed in PHP.
PHP and the basic syntax of the database has a basic understanding of the recommendation of a full project PHP book?? I really want to learn PHP
"PHP and MySQL Web development" This "PHP Bible", compared, "0 basic PHP" compared to beginners, read this book is easy to feel the author is written attentively.
This book is actually one of the 0 Basic programming series, and the rest is pretty good. The
content is well designed. There is a preface, written very pertinent, is the programmer veteran's advice to rookie, excerpts from this:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Some points to be aware of when learning programming:
1. Do not rote grammar: many beginners try to memorize all kinds of grammar, in fact, this is extremely wrong, the program development of grammar ﹑ specification is particularly many, it is impossible to remember, you just know that there is such a function can be, when needed to read books, or find help files, This saves time and effort.
2. More hands, more practice: Only know the dead moreing people, is not to become a master of development, only a lot of computer programming, in order to improve the understanding of the program in practice.
3. Encounter problems, first try to solve their own: first use one in the time, try to solve, really do not go to find someone to help, do not encounter problems immediately ask for help, this will never improve much.
4. Multi-use Google,baidu: The network is a big knowledge base, is the best teacher, you have encountered problems, others have encountered, more to search for it.
4. Read other people's source code: To understand other people's design ideas, and constantly melt into use. The disadvantage of the
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Book is that there is no line label in front of the code, and in the interpretation of the code, "on XXX lines, ", a larger blunder.
Summary: In terms of knowledge, "0 basic PHP" may not be complete, but, we need not a dictionary, we need a persuasive book, learn to be interested, is not it?
http://www.bkjia.com/PHPjc/875391.html www.bkjia.com true http://www.bkjia.com/PHPjc/875391.html techarticle PHP Basic Syntax Summary, PHP Basic syntax one, what can PHP do? What can PHP do? I think it is very strong, as long as I can think of, it can do, but my technical ability is not ╮ (╯ ...