Jos*_*osh 47
您可以使用file_get_contents()读取整个文件,执行str_replace(),然后使用file_put_contents()将其输出.
示例代码:
<?php
$path_to_file = 'path/to/the/file';
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace("\nH",",H",$file_contents);
file_put_contents($path_to_file,$file_contents);
?>
Run Code Online (Sandbox Code Playgroud)
Gum*_*mbo 13
有几个函数可以读写文件.
您可以阅读文件的内容file_get_contents
,执行替换str_replace
并将修改后的数据放回file_put_contents
:
file_put_contents($file, str_replace("\nH", "H", file_get_contents($file)));
Run Code Online (Sandbox Code Playgroud)