Before this tutorial, I will not talk about the common uses of PHP in a long and uniform way. Regarding what is a variable, what is a judgment statement, etc., please check the relevant information by yourself. This tutorial is intended for people who have a programming foundation and are new to PHP. The article is relatively simple. Mainly depends on the structure. Please study it yourself for details
PHP environment installation:
The usual combination of PHP is: MySql+PHP+Apche, there is also IIS+PHP+MySQL or SqlServer
Of course we can choose the combination package for installation. Newbies are advised to install AppServ or phpnow, etc.
You can use this installation and running under iis to support php. Mysql needs to be installed.
You can also install each part yourself. Then configure it yourself.
PHP download address: http://museum.php.net/php5/
Apche download address: http://prdownloads.sourceforge.net/appserv/appserv-win32-2.5.10.exe ?download
MySQL download address: http://www.mysql.cn/
Configuration and installation tutorial: http://wenku.baidu.com/view/c6118b1810a6f524ccbf85f9.html
Or http://www .jb51.net/article/33062.htm
Writing tools: It is recommended to use Notepad++ or dreamweaver cs4
========================== ===========================================
Syntax:
The syntax of PHP is very simple - just look at the code: This is how PHP code is declared. Note: ?> can also be written like this, but it is not recommended.
Mark the end of a statement: The semicolon marks the end of a statement ";" -- a ";" semicolon should be used after each statement to indicate the end.
============ ================================================== ========
Comments in PHP: --See the code in the tutorial
for details. Comments in PHP have single-line comments: //This is the comment
and the large module comment: /* This is a comment*/
============================================ ===========================
Variables:
PHP variables are loose. But it is also case-sensitive, so everyone should pay attention to this. There is no need to declare it before using it - PHP will automatically convert the variable into the correct data type based on the way the variable is declared.
Declaring variables in PHP is declared using the $ keyword - all variables are identified by $
Variable naming rules:
Variable names must start with a letter or underscore "_".
Variable names can only contain alphanumeric characters and underscores.
Variable names cannot contain spaces. If the variable name consists of multiple words, they should be separated by underscores (such as $my_string) or start with a capital letter (such as $myString).
Note: (Basically all programming languages have similar variable naming rules!)
Example:
运算符 | 说明 | 例子 | 结果 |
---|---|---|---|
+ | Addition | x=2 x+2 |
4 |
- | Subtraction | x=2 5-x |
3 |
* | Multiplication | x=4 x*5 |
20 |
/ | Division | 15/5 5/2 |
3 2.5 |
% | Modulus (division remainder) | 5%2 10%8 10%2 |
1 2 0 |
++ | Increment | x=5 x++ |
x=6 |
-- | Decrement | x=5 x-- |
x=4 |
运算符 | 说明 | 例子 |
---|---|---|
= | x=y | x=y |
+= | x+=y | x=x+y |
-= | x-=y | x=x-y |
*= | x*=y | x=x*y |
/= | x/=y | x=x/y |
.= | x.=y | x=x.y |
%= | x%=y | x=x%y |
比较运算符
运算符 | 说明 | 例子 |
---|---|---|
== | is equal to | 5==8 returns false |
!= | is not equal | 5!=8 returns true |
> | is greater than | 5>8 returns false |
< | is less than | 5<8 returns true |
>= | is greater than or equal to | 5>=8 returns false |
<= | is less than or equal to | 5<=8 returns true |
逻辑运算符
运算符 | 说明 | 例子 |
---|---|---|
&& | and | x=6 y=3 (x < 10 && y > 1) returns true |
|| | or | x=6 y=3 (x==5 || y==5) returns false |
! | not | x=6 y=3 !(x==y) returns true |
Program judgment statement:
It is the same as C#, java, C and other judgment statements. There are if..else/else..if and switch statements - look directly at Code
MyEcho2("Heheheha!"); //Output: Hehehaha!
?>
That’s all for now...if you have time , I will write down the commonly used applications of PHP. Advanced section. (Including sessions, cookies, object-oriented, common functions, etc.)