-1

我有两个文件

File1.php 和 File2.php

$hello = file_get_contents("file1.php");
file_put_contents("hello.txt",$hello);

file1.php 包含一些示例文本,如下所示

hello \r\n hi \r\n how are you.

我需要的是当我将内容放入 hello.txt 时,我希望这些单词出现在新行中,如下所示

hello 
hi
how are you.

我尝试使用 \r\n 和 \n 但没有任何效果

注意: file1.php 是另一个页面源的 file_get_contents..i 只能替换<br>标签, \r\n这只是一个例子。我还有其他一些复杂的部分要做。

4

3 回答 3

3

做一个str_replace

$hello = str_replace('\r\n', "\r\n", $hello)

请注意,单引号和双引号是不同的......在这里阅读不同之处:http: //php.net/manual/en/language.types.string.php

于 2013-05-21T14:53:08.570 回答
1

I think you should put something at the end of each line,

then you can replace it whit :

   str_replace

function, i think this will work

str_replace('[EndOfLine]', "\r\n", $string);
于 2013-05-21T15:06:45.487 回答
-1

使您的 File1.php 包含此文本

hello 
hi
how are you.

您的代码将完美运行!

于 2013-05-21T14:46:46.787 回答