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;
}
posted @ 2018-11-14 00:53  MrBear  阅读(2313)  评论(0编辑  收藏  举报