1. 程式人生 > >PHP中替換函式str_replace()

PHP中替換函式str_replace()

str_replace(find,replace,string,count)
find:需要替換的值
replace:將要替換的值,
string:被替換的字串
count:同級替換的次數

如果需要把資料庫中儲存的帶回車以及空格的文章,按照其原來的樣式顯示在html中,可以使用此函式,

function htmtocode( $content ) {
    $content = str_replace( '\n','<br/>',str_replace(' ','&nbsp;' ,$content) );
    return $content;
}