是否有一些PHP函數或類允許我像字符數組一樣讀取文件?PHP中的隨機訪問文件
例如:
$string = str_split('blabla');
$i = 0;
switch($string[$i]){
case 'x':
do_something();
$i++;
case 'y':
if(isset($string[++$i]))
do_something_else();
else
break;
case 'z':
// recursive call of this code etc..
}
我知道,我可以使用$string = file_get_contents($file)
,但問題是,我得到用於微小800K的文件(如80MB)的內存量巨大。
所以,我可以以某種方式「流」在我的代碼上面的文件與某種類型的數組訪問,如類我會調用isset()時自動從文件讀取數據? :)
不,它不是真正的隨機。我將只向前移動$ i ... – Alex