php 空格回车转成html格式

来源:互联网 发布:怎么找淘宝差评师 编辑:程序博客网 时间:2024/06/08 13:55
/*** 换行符等转换成html格式输出**/function code_to_string($str){    /*    * \t:水平制表(跳到下一个Tab位置)意思是按一个tab    * \n:换行    * \r:回车,将当前位置移到本行开头    */    $pre = array( " " , " " , "\t" , "\n" , "\r" );    $to = array( '&nbsp;' , '&nbsp;&nbsp;' , '&nbsp;&nbsp;&nbsp;&nbsp;' , '<br>' , '<br>' );    return str_replace ( $pre , $to , $str );}