麻辣家族討論版版's Archiver

小誌 發表於 2011-4-19 18:48

6-3-3 將資料寫入檔案

[color=DarkRed][size=4][b]6-3-3   將資料寫入檔案[/b][/size][/color]
要將資料寫入檔案最簡單了,直接使用fwrite()或fputs()函數就行了:
fwrite() 與fputs()函數格式[code]int fwrite ( resource handle, string string [, int length])
int fputs ( resource handle, string string [, int length])[/code]fwrite()與fputs()函數格式都一樣,使用的方式當然也都一樣,筆者是比較喜歡fwrite()函式啦!例如:[code]<?
$myfile="writetest1.txt";
$word="我是被寫入的資料";

    $file=fopen($myfile,"w");
   fwrite($file,$word);
?>[/code]如果沒設定寫入長度參數,代表要將全部的資料都寫入到檔案中,若指定長度參數,則寫入的資料就只有我們所指定的長度資料:[code]<?
$myfile="writetest1.txt";
$word="我是被寫入的資料";

    $file=fopen($myfile,"w");
   fwrite($file,$word,4); //檔案內只有”我是”
?>[/code]

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供