2012-01-04 18 views
1
<textarea rows="18" cols="80" style="resize:none;"> 
<?php 
    $str = str_replace('<br>', '\n', 'some text<br><br>another line of text'); 
    echo($str); 
?> 
</textarea> 

輸出是 n沒有文字方面的工作

some text\n\nanother line of text 

這是我想要的輸出。

some text 

another line of text 

有人知道這個問題嗎? 在此先感謝

回答

11

單引號中的反斜槓是從字面上解釋的。你想雙引號:

$str = str_replace('<br>', "\n", 'some text<br><br>another line of text'); 
///      ^^ 

有關不同的方法來寫字符串常量在PHP的詳細信息,請參閱official documentation

+0

謝謝這個作品 – 2012-01-04 02:05:21