Home >Backend Development >PHP Problem >How to modify txt file in php
How to modify the txt file in php: first use the fopen() function to open the txt file; then use the fputs() function to write the content into the opened file. The fputs() function stops when it reaches the specified length or reaches the end of the file.
fputs() function writes the contents to an open file. The function will stop running when it reaches the specified length or reaches the end of file (EOF), whichever comes first.
(Recommended tutorial: php graphic tutorial)
If the function is successfully executed, the number of bytes written will be returned. On failure, returns FALSE.
Syntax:
fputs(file,string,length)
Parameters:
php video tutorial)
Implementation code:$path="wifi_customer_settings.txt"; $wifissid2=$_POST['wifissid']; $wifipwd2=$_POST['wifipwd']; $arr=array("wifiSSID=".$wifissid2,"\n","wifiPWD=".$wifipwd2); $fp=fopen($path, 'w'); fputs($fp,$arr[0]); fputs($fp,$arr[1]); fputs($fp,$arr[2]); fclose($fp);
The above is the detailed content of How to modify txt file in php. For more information, please follow other related articles on the PHP Chinese website!