How to modify txt file in php

王林
Release: 2023-03-04 14:26:01
Original
3177 people have browsed it

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.

How to modify txt file in php

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)
Copy after login

Parameters:

  • ##file Required. Specifies the open file to be written to.

  • #string Required. Specifies the string to be written to the open file.

  • #length Optional. Specifies the maximum number of bytes to be written.

(Learning video recommendation:

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!