打开文件,替换字符串并另存为新文件

时间:2012-12-21 16:13:59

标签: php preg-replace file-get-contents str-replace

我希望在php中打开一个文件,替换其中的一个字符串并将其保存为新文件。

我使用的是一个简单的代码:

<?php

//open file and get data
$data = file_get_contents("File_Name.txt");

// do tag replacements or whatever you want
$data = str_replace("<tag1>","<tag2>", $data);

//save it back:
file_put_contents("DEST_FILE.txt", $data);

?>

但问题是它在目标文件中插入了很多反斜杠,如下所示:

\ "Hello"
\"MSXML2.XMLHTTP\"

如何避免不必要的反斜杠?

0 个答案:

没有答案
相关问题