W3school PHP Tutorial Refinement (ii) PHP Advanced _php Tutorial

Source: Internet
Author: User
1 Date ()

1.1 Date () function

Syntax: Date (Format,timestamp)

Format: Required. Specifies the format of the timestamp.

Timestamp: Optional. Time stamp is specified. The default is the current date and time.

1.2 Timestamp (Timestamp)

Number of seconds since 1970.1.1 (00:00:00GMT)

1.3 Formatting Dates

The format parameter of the date () function specifies how the date/time is formatted

D: Day of the Month (01-31)

M: Current month, in Digital (01-12)

Y: Current year (four digits)

"; Echo Date (" y-m-d ");? >1.4 adding timestamps

The timestamp parameter of the date () function specifies a timestamp

1.5 Mktime () function

The Mktime () function returns the UNIX timestamp for the specified date

Syntax: Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)

2 Referencing files

2.1 Include () function

2.2 Require () function

and include () are handled differently: the Include () function generates a warning (but the script continues), and the Require () function generates a fatal error (fatal error) (the script stops executing after the errors occur)


3 File Processing

3.1 Open File fopen () function

The first parameter contains the name of the file to open

The second parameter specifies which mode to use to open a file

Mode
Describe

R
Read-only. Start at the beginning of the file.

r+
Read/write. Start at the beginning of the file.

W
Write only. Open and empty the contents of the file, or create a new file if the file does not exist

w+
Read/write. Open and empty the contents of the file, or create a new file if the file does not exist

A
Additional. Opens and writes to the end of the file, creating a new file if the file does not exist

A +
Read/Append. Preserves file content by writing content to the end of a file

X
Write only. Creates a new file. Returns False if the file already exists

x+
Read/write. Creates a new file. If the file already exists, it returns false and an error. Returns 0 (false) if fopen () cannot open the specified file

3.2 Closing the file fclose () function

3.3 Detecting end-of-file feof () function

3.4 Read File fgets () function line by row

After the function is called, the file pointer moves to the next line

";} Fclose ($file);? >3.5 character read file fgetc () function

After the function is called, the file pointer moves to the next character

4 File Upload
4.1 Creating a form

4.2 Upload script Global array $_files

0) {echo "Error:". $_files["File" ["Error"]. "
";} Else{echo "Upload:". $_files["File" ["Name"]. "
"; echo" Type: ". $_files["File" ["type"]. "
"; echo" Size: ". ($_files["File" ["Size"]/1024). The Kb
"; echo" Stored in: ". $_files["File" ["Tmp_name"];}? The first parameter of the >$_files array is the input name of the form, and the second subscript can be:

Name: filename of the file being uploaded

Type: Types of files being uploaded

Size: Sizes of uploaded files

Tmp_name: The name of the temporary copy of the file stored on the server

Error: Wrong code caused by file upload

4.3 Upload limit

Limit upload. gif or. jpeg files, the file size must be less than 20KB:

0) {echo "Error:". $_files["File" ["Error"]. "
";} Else{echo "Upload:". $_files["File" ["Name"]. "
"; echo" Type: ". $_files["File" ["type"]. "
"; echo" Size: ". ($_files["File" ["Size"]/1024). The Kb
"; echo" Stored in: ". $_files["File" ["Tmp_name"];} Else{echo "Invalid file";}}? >
4.4 Save the uploaded file

Copy the temporary copy of the uploaded file created in the temporary folder from the example above to another location so that it disappears at the end of the script

0) {echo "Error:". $_files["File" ["Error"]. "
";} Else{echo "Upload:". $_files["File" ["Name"]. "
"; echo" Type: ". $_files["File" ["type"]. "
"; echo" Size: ". ($_files["File" ["Size"]/1024). The Kb
"; echo" Temp file: ". $_files["File" ["Tmp_name"]. "
"If (file_exists (" upload/"). $_files["File" ["Name"])) {echo $_files["file" ["Name"]. "already exists.";} Else{move_uploaded_file ($_files["file"] ["Tmp_name"], "upload/". $_files["File" ["name"]); echo "Stored in:". " Upload/". $_files["File" ["Name"];}}} Else{echo "Invalid file";}? >

5 Cookies
5.1 Creating a cookie Setcookie () function

Syntax: Setcookie (name, value, expire, path, domain);

5.2 Retrieving the value of a cookie

Use the Isset () function to confirm that the cookie has been set:

";} Else{echo "Welcome guest!
";}? >5.3 Delete Cookies

6 Session Variables
6.1 Starting Session Sessions

6.2 Storing Session Variables

6.3 End Session

The 7 mail () function is used to send e-mail from a script.
Syntax: Mail (to, subject, message, headers, parameters)

Parameters
Describe

To
Necessary. Specify email recipients.

Subject
Necessary. Specify the subject of email. Note: This parameter cannot contain any new line characters.

Message
Necessary. Define the information to be sent. You should use LF () to separate the lines.

Headers
Optional. Specify additional headings, such as From, Cc, and Bcc. Additional headings should be delimited with CRLF ().

Parameters
Optional. Specify additional parameters for the mail sender.

7.1 Example

?>

http://www.bkjia.com/PHPjc/478821.html www.bkjia.com true http://www.bkjia.com/PHPjc/478821.html techarticle 1 Date () 1.1 date () function syntax: Date (FORMAT,TIMESTAMP) format: Required. Specifies the format of the timestamp. Timestamp: Optional. Time stamp is specified. The default is the current date and time. ...

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