PHP Basic Syntax 3

Source: Internet
Author: User

File system Determines whether a file exists
    1. If you just judge the existence of the file, using file_exists, file_exists can not only determine whether the file exists, but also can determine whether the directory exists, from the function name can be seen,
    2. Is_file is the exact judge of whether a given path is a file.
    3. It is more accurate to use is_readable and is_writeable to determine whether a file is readable or writable, based on whether the file exists.

write content to file
    1. The simplest way is to use file_put_contents.
    2. Use fwrite for file writing.

Get the file modification time

The file has many meta attributes, including: The owner of the file, creation time, modification time, last access time, and so on.

Fileowner: Get the owner of the file

Filectime: Gets the creation time of the file

Filemtime: Gets the file modification time

Fileatime: Get access time for a file

get the size of the file

The size of the file can be obtained through the FileSize function, and the file size is expressed as a number of bytes.

The size of the directory is not available through simple functions, and the size of the directory is the sum of all subdirectories and file sizes in that directory, so it is necessary to recursively calculate the size of the directory by recursive means.

Deleting Files

1. Use the unlink function for file deletion.

2. Delete a folder using the RmDir function, the folder must be empty and will fail if it is not empty or has no permissions.

3. If there is a file in the folder, you can cycle through all the files in the directory and then delete the directory, and the loop delete can use the Glob function to traverse all the files.

Date and timegets the current UNIX timestamp

$time = time ();

echo $time;//1396193923, this number represents 1,396,193,923 seconds from January 1, 1970 00:00:00 to the time I output this script.

get the current date

Function Description: Date (timestamp format, specified timestamp "default is the current date and time, optional")

Return value: function date and time

echo Date (' y-m-d ', ' 1396193923 ');

echo Date (' y-m-d ');

Unix timestamp of date acquired

It represents the sum of the seconds from January 1, 1970 00:00:00 to the current time.

echo strtotime (' 2014-05-01 ');

converts a formatted date string to a Unix timestamp

Echo Strtotime ("Now"), or//is equivalent to the current date and time of the English word, and converts the date time to a Unix timestamp. This effect is the same as echo time ().

Echo strtotime ("+1 seconds") is equivalent to adding the current date and time to 1 seconds and converting the date time to a Unix timestamp. This effect is the same as echo time () +1.

Echo strtotime ("+1 Day"), or the equivalent of adding the current date and time to 1 days.

Echo strtotime ("+1 Week");//equivalent to the current date and time is added 1 weeks.

Echo strtotime ("+1 Week 3 days 7 hours 5 Seconds"), or//equivalent to the current date and time is added 1 Weeks 3 day 7 hours 5 seconds.

format Greenwich (GMT) Standard Time

We are now in the China time Zone is East eight, leading GMT 8 hours, sometimes called gmt+8, then the server run the following script to return the time should be this:

The current time is assumed to be 2014-05-01 15:15:22

echo Date (' y-m-d h:i:s ', Time ()); Output is: 2014-05-01 15:15:22

echo gmdate (' y-m-d h:i:s ', Time ()); The output is: 2014-05-01 07:15:22 because GMT is now in China time zone minus 8 hours, so compared to the present time is less than 8 hours

Exception handling

Database operations connect to MySQL database

Execute Query

PHP Basic Syntax 3

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.