如需移除,請網站管理者移除.
其實PHP有個內建函數叫做 nl2br ,靠這個函數就可以囉
<?php $result = nl2br($_POST["content_with_return"]);
<?php $result = nl2br($_POST["content_with_return"]); 但是編輯時,總不能在 <textarea> 看到一個的<br />,不只不好看,對電腦不熟的也不知道那是啥,所以必須替換回來,這我第一個想到的是用 str_replace ,不過之後在此網站有看到正規表達式的解法,所以兩者都附上
str_replace:
<?php $result = str_replace(chr(13).chr(10), "<br />",$content_with_br);
<?php $result = str_replace(chr(13).chr(10), "<br />",$content_with_br); preg_replace:
<?php function br2nl($text){ return preg_replace('/<br\s*?/??>/i','',$text); } //此方法來自 http://www.jb51.net/article/35076.htm
回覆