TAILIEUCHUNG - Beginning PHP 5.3 phần 5

Chức năng fread () có thể được sử dụng để đọc một chuỗi ký tự từ một tập tin. Nó có hai đối số: một tập tin xử lý và số lượng ký tự để đọc. Chức năng đọc số quy định của ký tự (hoặc ít hơn nếu kết thúc của tập tin là đạt) và trả về cho họ như là một chuỗi. Ví dụ, HTML:: QuickForm (được nêu tại Chương 15) | Chapter 11 Working with Files and Directories file_put_contents Writes a whole string to a file without needing to open it fpassthru Displays the contents of an open file readfile Displays the contents of a file without needing to open it fseek Moves the file pointer to a specific location within an open file ftell Returns the position of the file pointer rewind Moves the file pointer to the start of the file As you can see PHP gives you many different ways to read and write to files so you can always find a function to suit your needs Reading and Writing Strings of Characters The fread function can be used to read a string of characters from a file. It takes two arguments a file handle and the number of characters to read. The function reads the specified number of characters or less if the end of the file is reached and returns them as a string. For example handle fopen r data fread handle 10 This code reads the first ten characters from and assigns them to data as a string. When working with binary files a character is always one byte long so ten characters equals ten bytes. However this doesn t apply when working with Unicode files where each character may take up several bytes. In this case reading ten characters may in fact result in reading say twenty bytes from the file. After fread has finished the file pointer which holds the current position in the file moves forward in the file by the number of characters read. So after the previous example code runs the file pointer moves forward to ten characters after the start of the file. If you repeat the same call to fread you ll get the next ten characters in the file. If there are less than ten characters left to read in the file fread simply reads and returns as many as there are. By the way if you want to read only one character at a time you can use the fgetc function. fgetc takes a single argument a file handle and returns just one character from the file it points to it returns false when

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.