Share with you the first two hours I learned PHP (for beginners) (scatter)
Learn from:
PHP Code
http://www.w3school.com.cn/php/
The 1.php file must be:
The statement is written here
?>
2.echo Output Function Method: Echo "abc"
3. Defining variables: $ variable name = variable Value
4. Two variables combined output with "." Connection Example: Echo $ variable 1. Variable 2
The 5.strlen () function is the length that represents the value of the variable
For example Echo strlen ("Hello world!"); Output 12
The 6.strpos () function represents the position of the retrieved string to find the string in a string
7. Operators
Arithmetic operators
Operator Description Example Results
+additionx=2
X+24
-subtractionx=2
5-x3
*multiplicationx=4
x*520
/division15/5
5/23
2.5
%modulus (Division remainder) 5%2
10%8
10%21
2
0
++incrementx=5
X++x=6
--decrementx=5
X--x=4
Assignment operators
Operator Description Examples
=x=yx=y
+=x+=yx=x+y
-=x-=yx=x-y
*=x*=yx=x*y
/=x/=yx=x/y
. =x.=yx=x.y
%=x%=yx=x%y
Comparison operators
Operator Description Examples
==is equal to5==8 returns False
!=is not Equal5!=8 returns True
>is Greater Than5>8 returns false
<8 returns="">
>=is greater than or equal to5>=8 returns false
<=is less than or equal to5<=8 returns True
logical operators
Operator Description Examples
&&andx=6
Y=3
(x < && y > 1) returns True
|| Orx=6
Y=3
(x==5 | | y==5) returns false
!notx=6
Y=3
! (x==y) returns True
8. Function date ("D"); Time function returns the information of the day
9. Definition set: $name = Array ("Liu", "Chenghaiyan", "myphp");
10.for Cycle
PHP Code
$i =0; for ($i =1;i<5;i++) { echo "See Me Go First". $i. " Side
”;}
11.foreach Cycle
PHP Code
$arr = Array ("One", "one", "three"); foreach ($arr as $value) { echo "I changed the Collection project". $value}
12. Function definition Keywords: functions
PHP Code
13.function W ($name 1, $name 2)--=> release parameters
14. return value in function
15.$_post["name"] or $_get["name"] is the value for the form submission
$_cookie["name"] get the value of a COOKIE
17.$_request["Name"] contains the $_post $_get $_cookie
18.data (Format,timesamp);
function Meaning: Time
Parameter meaning: Format: Mandatory, time-specified
Timesamp
Example: Echo data ("y/m/d");
echo Data ("Y.M.D");
echo Data ("y-m-d");
Above output:
2006/07/11
2006.07.11
2006-07-11
Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
function meaning: Point in time
IS_DST is an optional parameter other parameters are optional
20.include ("head.php") function
Set the head.php file as a header file
For example:
PHP Code
Welcome to my home page
Some text
21.require ("head.php") function
Almost the same as the include () function, just wrong way of handling
Include executes the following PHP code in addition to the error and require immediately returns
22.fopen (); Open File in PHP page
There are two parameters: parameter A is the file path
Parameter b asks file open mode
Here is an explanation for parameter B:
"R"--=> read-only, starting at the beginning of the file
"r+"--=> Read and write, beginning with the card header of the file
"W"--=> write only, open the file and empty the contents of the file, if the file does not exist create
"w+"--=> read/write, open the file and empty the contents of the file, if the file does not exist create
"A"--=> append, open the file and write to the end of the file, create a new file if the file does not exist
"A +"--=> read/Append, write content to the end of the file, and keep the file
"X"--=> write-only create file, return False if file exists
"x+"--=> read/write. Create file if the file already exists, it returns false and an error
Note *: If fopen () cannot open the specified file then play 0 (false)
Example 1: $file =fopen ("D:/abc.txt", "R");
Example 2: $file =fopen ("D:/abc.txt", "R") or exit ("Unable to open file!");
Note: This example pops up if the file cannot be opened
23.feof ($file) to retrieve whether the end of the file has been reached
Note: When the permission is: W, a, x, the file cannot be opened