更改php文件中的行

时间:2015-08-07 12:07:55

标签: php file variables

例如我有这个php文件:

{
$data= 'anydata';

$age = '33';

$site ='mysite';

$name = 'anyname'

}

问题:如何使用php更改字符串?

1 个答案:

答案 0 :(得分:1)

fgets,从手册页here

中读取一行

fwrite,来自手册页here

取消链接,来自手册页here

重命名,来自手册页here

chmod,来自手册页here

1. Open file1 (in file), file2 (outfile)
2. use fgets reading single lines (the next line) from file1
3. need to modify that string? do so.
4. use fwrite to write string to file2 (just that line)
5. loop back to 2 when not end-of-file (eof) of file1
6. close file1 and file2
7. unlink (delete) file1
8. rename file2 to file1 name
9. chmod accordingly