开发者

How to replace \r\n in textarea

PHP Code

<?php
$content = "check1\r\ncheck2\r\ncheck3\r\nend..."   
$order   = array("\r\n");
$replace = "\n";
$content= str_replace( $order, $replace, $content);
$smarty->assign('content', $content);
?>

View page (a smarty template)

<textarea>{$content}<textarea>

开发者_如何学PythonOutput:

check1\r\ncheck2\r\ncheck3\r\nend...

I expect output like below

check1
check2
check3
end...

inside the textarea. I had replaced \r\n into \n, but even then I can't get my desired output. Whats wrong in my code? Thank you in advance.


It looks like you're having a similar problem to this.

If I'm reading correctly, try:

<textarea>{$content|stripcslashes}<textarea>


I'm no Smarty guru, but you might want this in your template instead:

<textarea>{$content|stripslashes}<textarea>


This replaces all \r\n with \n.

$content = str_replace("\r\n", "\n", $content);

I have used that successfully a couple of days ago, and they come out correctly in a text field.


I had the same problem with the \r\n, but I had to add extra backslashes to the search argument (i.e., \r\n becomes \\r\\n) to make it work:

$content = str_replace("\\r\\n","\r\n",$content);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜