Home >Backend Development >PHP Problem >How to modify txt file in php

How to modify txt file in php

王林
王林Original
2020-08-15 13:53:493401browse

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)

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);

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!

Statement:
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 admin@php.cn