php使用str_replace實(shí)現(xiàn)輸入框回車替換br的方法
更新時間:2014年11月24日 15:28:46 投稿:shichen2014
這篇文章主要介紹了php使用str_replace實(shí)現(xiàn)輸入框回車替換br的方法,可實(shí)現(xiàn)使用\\n替換成br的方法,需要的朋友可以參考下
本文實(shí)例講述了php使用str_replace實(shí)現(xiàn)輸入框回車替換br的方法,分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
在我們用textarea時會發(fā)現(xiàn)回車與空格是不可看到的,所以我們利用str_replace函數(shù)將php中的\\n替換成br就可以了,有需要的朋友可以參考一下,代碼如下:
復(fù)制代碼 代碼如下:
function htmtocode($content) {
$content = str_replace("n", "<br>", str_replace(" ", " ", $content));
return $content;
}
$content = str_replace("n", "<br>", str_replace(" ", " ", $content));
return $content;
}
先替換掉空格,再替換回車,相當(dāng)于如下代碼:
復(fù)制代碼 代碼如下:
function htmtocode($content) {
$content = str_replace(" ", " ", $content);
$content = str_replace("n", "<br>",$content);
return $content;
}
$content = str_replace(" ", " ", $content);
$content = str_replace("n", "<br>",$content);
return $content;
}
希望本文所述對大家的PHP程序設(shè)計有所幫助。
相關(guān)文章
PHP跳轉(zhuǎn)頁面的幾種實(shí)現(xiàn)方法詳解
本篇文章是對PHP跳轉(zhuǎn)頁面的幾種實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
PHP標(biāo)準(zhǔn)類(stdclass)用法示例
這篇文章主要介紹了PHP標(biāo)準(zhǔn)類(stdclass)用法,結(jié)合實(shí)例形式分析了php內(nèi)置標(biāo)準(zhǔn)類的原理與使用方法,需要的朋友可以參考下2016-09-09

