?? ?? ??? ?? ??
?? ????? ???? ??? ??? ????. ?? ????? ?? ??? ?????.
??? ???????.
?? ?? Windows? d:xxxxxx???. ??: Windows? d:/xxx/xxx? ?????
Linux? ?? ??? /home/xxx/xxx???. ??: Linux?? homexxxxxx? ??? ??
??? ????? ?? ????? , ????? ??? ?? ???? d:xxxxxx? ?????. ??? ? 2?? ??? ??? ??? ? /? ??? ??? ???? Linux? Windows?? ??? ??? ??? ??? ? ????.
??? ?????:
DIRECTORY_SEPARATOR
?? ??? ??? ???? ??? ?? ??? ?????.
FILE? PHP ??? ?? ????? ???? ???? ??? ??? ????. ??? ?? FILE? ?? ??? ?? ??? ? ????.
??? FILE? ???? ?? ??? ?? ??? ?? ??? ???? FILE? ??? ? ????.
<?php $_current_file = str_replace(array('/', '\'), DIRECTORY_SEPARATOR, __FILE__); define('__CUR_FILE__', $_current_file); echo __CUR_FILE__; ?>
?? ??? ?? ??
rewind(??? ??)
??: ???? ???? ?????
fseek(??? ??, int offset [, int from_where])
??: ?? ???? ?? ?????. ??
?? ???? fread? ??? ??? ???? ???? ?? ?????. ??? ??? ??? ????. ??? ?? ??? ?? ???? ?? ????.
??????????????????????????????????????????????????????????????????????? ??>2 . >3.??? ?? C? ?? ????? ?? ?????.
demo.txt ??? ?? ??? ?????.
abcdeefghijklk
opqrstuvwxyz
12345678??? ??? ? ????.<?php $fp = fopen('output.txt', 'r+'); //讀取10個字符 echo fread($fp,10); //指針設(shè)置回到開始處 rewind($handle); //再讀取10次看看輸出的是什么 echo fread($fp,10); //文件指針向后移動10個字符 echo fseek($fp,10); //再看看文件中輸出的是什么 echo fread($fp,10); fclose($handle); ?>?? ??? fseek? ??? ???? ???? ???? ?? ? ? ????. ??? ???? ?? ??? ?? ???? ?????.
??? ???? ???? ??? ?? ? ? ????. fseek ?? ?? ?? ?????.
?? ?? ?? ???? ?? ???? ?????.
filesize? ??? ??? ?????
<?php $filename = 'demo.txt'; echo $filename . '文件大小為: ' . filesize($filename) . ' bytes'; ?>
?? ??? ?? ?? ??
?? ?? ??? ???? ?? ?? ??, ?? ??
?? ?? ??? ???? ?? ??? ?????.
demo.txt ??? ?? ??? ?????.
abcdeefghijklk
opqrst
uvwxyz
12345678
<?php //以增加的r模式打開 $fp = fopen('demo.txt','r+'); //你分發(fā)現(xiàn)每次只讀一個字符 echo fgetc($fp); //我要全部讀取可以,讀取一次將結(jié)果賦值一次給$string while($string = fgetc($fp)){ echo $string; } ?>
fgets? ?? ???? ? ?? ???. a time :
<?php //以增加的r模式打開 $fp = fopen('demo.txt','r+'); //你分發(fā)現(xiàn)每次只讀一個字符 echo fgets($fp); echo fgets($fp); echo fgets($fp); echo fgets($fp); ?>
? ??? ???? ? ??? ? ?? ? ?? ??? ?? ? ? ????. ?? ?? ??? ?????.
???? ?? ???? ??? ???????.
<?php //打開我們上面的demo.txt文件 $file = fopen("demo.txt", "a+"); //你可以數(shù)數(shù)20個字有多長,看看是不是達到效果了 echo ftruncate($file,20); fclose($file); ?>
?? ???? ????? ?? ???? ??? ? ??? ?? ? ? ?????.
???