TAILIEUCHUNG - Professional Information Technology-Programming Book part 81

Tham khảo tài liệu 'professional information technology-programming book part 81', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Reading and Writing Files Now let s see how to read and write files from PHP. Simple Methods for Reading and Writing Files PHP provides some simple high-level functions that can open a file and grab its contents or write data to a file in a single operation. To read the contents of a file into a string variable you use file_get_contents. The argument is a filename which can contain a relative or absolute path. The following statement reads a file called file. txt into the variable data data file_get_contents An optional second Boolean argument can be set to TRue to search the include path for the given filename. You will see how to configure the include path in Lesson 23 PHP Configuration. The function file_put_contents simply dumps the contents of a variable to a local file. Its arguments are the filename to write to and the data to write. The following statement writes the value of data to file. txt file_put_contents data Lower-Level File Access The functions file_get_contents and file_put_contents are high-level functions that perform a number of steps that can be done individually with lower-level PHP functions. Although in many cases reading the entire contents of a file or writing data to a file is the task you will want to perform PHP provides a flexible way to interface with the filesystem. All file access begins with a file handler which is established with the fopen function. The arguments to fopen are a filename and the mode in which to open the file. The available modes are shown in Table . Table . File Mode Arguments to fopen Mode Description r Opens for reading only from the beginning of the file. r Opens for reading and writing from the beginning of the file. w Opens for writing only overwrites the old file if one already exists. w Opens for writing and reading overwrites the old file if one already exists. a Opens for writing only and appends new data to the end of the file. a Opens for reading and writing at the end of the

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.