(PHP 4 >= 4.3.2, PHP 5, PHP 7, PHP 8)
streamWrapper::stream_read — 從串流讀取
count
應從目前位置返回多少位元組的資料。
如果可用的位元組數少於 count
,則應返回盡可能多的可用位元組數。如果沒有更多可用資料,則應返回空字串。若要表示讀取失敗,應返回 false
。
注意:
在呼叫 streamWrapper::stream_read() 之後會直接呼叫 streamWrapper::stream_eof() 來檢查是否已到達檔案結尾(EOF)。如果未實作,則假設已到達檔案結尾(EOF)。
當讀取整個檔案時(例如,使用 file_get_contents()),PHP 會在迴圈中呼叫 streamWrapper::stream_read(),然後呼叫 streamWrapper::stream_eof(),但只要 streamWrapper::stream_read() 返回非空字串,streamWrapper::stream_eof() 的回傳值就會被忽略。