2013-05-21 29 views
-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是另一頁source..i的的file_get_contents只能\r\n取代<br>標籤,這僅僅是一個例。我還有其他複雜的部分要做。

+0

我認爲你需要做這樣的事情'file_put_contents( 「hello.txt的」,$你好)。 「\ n」;' –

+0

當你替換時,你是否確保使用雙引號'''而不是單引號''''$ string =「Hello \ r \ nWorld」;''會是'Hello [ NEWLINE] World''''string ='Hello \ r \ nWorld';'將會是'Hello \ r \ nWorld'(文字字符); – h2ooooooo

+0

nope .. $ hello包含多個分隔線..如何工作 – Vishnu

回答

1

我覺得你應該把東西在每行的末尾,

,那麼你可以取代它白衣:

str_replace 

功能,我認爲這會工作

str_replace('[EndOfLine]', "\r\n", $string); 
-1

讓您File1.php包含本文

hello 
hi 
how are you. 

和您的代碼將很好地工作!

+0

的一個,它禁止其他頁面源的file_get_contents ..我只能用\ r \ n替換
標記 – Vishnu