Find and replace in a file

前端 未结 4 566
醉话见心
醉话见心 2020-12-05 05:00

I want to replace certain strings with another one in a text file (ex: \\nH with ,H). Is there any way to that using PHP?

4条回答
  •  我在风中等你
    2020-12-05 05:26

    There are several functions to read and write a file.

    You can read the file’s content with file_get_contents, perform the replace with str_replace and put the modified data back with file_put_contents:

    file_put_contents($file, str_replace("\nH", "H", file_get_contents($file)));
    

提交回复
热议问题