與讀取文件對應,PHP寫文件也具有兩種方式,最簡單的方式是采用file_put_contents。
$filename = './test.txt'; $data = 'test'; file_put_contents($filename, $data);
上例中,$data參數可以是一個一維數組,當$data是數組的時候,會自動的將數組連接起來,相當于$data=implode('', $data);
同樣的,PHP也支持類似C語言風格的操作方式,采用fwrite進行文件寫入。
$fp = fopen('./test.txt', 'w'); fwrite($fp, 'hello'); fwrite($fp, 'world'); fclose($fp);
寫入一個字符串到$filename文件中
在第4行后輸入:
$fp = fopen($filename, 'w'); fwrite($fp, 'hello world'); fclose($fp);
或者使用file_put_contents:
file_put_contents($filename, 'hello world');
請驗證,完成請求
由于請求次數過多,請先驗證,完成再次請求
打開微信掃碼自動綁定
綁定后可得到
使用 Ctrl+D 可將課程添加到書簽
舉報