Computer >> Máy Tính >  >> Lập trình >> PHP

hàm touch () trong PHP

Hàm touch () đặt thời gian truy cập và sửa đổi tệp. Nó trả về TRUE khi thành công hoặc FALSE khi thất bại.

Cú pháp

touch(filename, time, atime)

Tham số

  • tên tệp - Đặt tên của tệp.

  • thời gian - Đặt thời gian. Giá trị mặc định là giờ hệ thống hiện tại.

  • atime - Đặt thời gian truy cập. Giá trị mặc định là giờ hệ thống hiện tại.

Quay lại

Hàm touch () trả về TRUE khi thành công hoặc FALSE nếu không thành công.

Ví dụ

<?php
$myfile = "new.txt";
// changing the modification time to current system time
if (touch($myfile)) {
   echo ("The modification time of $myfile set to current time.");
} else {
   echo ("The modification time of $myfile can’t be updated.");
}
?>

Đầu ra

The modification time of new.txt set to current time.

Hãy để chúng tôi xem một ví dụ khác.

Ví dụ

<?php
$myfile = "new.txt";
$set_time = time() - 28800;
// changing the modification time
if (touch($myfile, $set_time)) {
   echo ("The modification time of $myfile updated to 8 hrs in the past.");
} else {
   echo ("The modification time of $myfile can’t be updated.");
}
?>

Đầu ra

The modification time of new.txt updated to 8 hrs in the past.