把空格替换成&nbsp;,把回车替换成<BR>
function chn_str_replace($needle,$string,$haystack)
{
$l = strlen($haystack);
$l2 = strlen($needle);
$l3 = strlen($string);
$news = "";
$skip = 0;
$a = 0;
while ($a < $l)
{
$ch = substr($haystack,$a,1);
$ch2 = substr($haystack,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40"))
{
if (substr($haystack,$a,$l2) == $needle)
{
$news .= $string;
$a += $l2;

else 
{
$news .= $ch.$ch2;
$a += 2;
}
}
else
{
if (substr($haystack,$a,$l2) == $needle)
{
$news .= $string;
$a += $l2;

else 
{
$news .= $ch;
$a++;
}
} // END IF
} // END WHILE
return $news;
}$str=chn_str_replace(" ","&nbsp;",$str);
$str=chn_str_replace(chr(13).chr(10),"<br>",$str);

解决方案 »

  1.   

    nl2br
    将换行字符转成 <br>。
    语法: string nl2br(string string);
    返回值: 字符串
    函数种类: 资料处理
    内容说明 
    本函数将换行字符转换成 HTML 换行的 <br> 指令。
    参考 
    htmlspecialchars()  htmlentities()  
      

  2.   

    HTML标记<per></per>原样输出,
    你怎样输入就怎样输出.
      

  3.   

    TO xcgh(晓刚) :
    $str="wwwwww
              wwwww
                 wwwwwwwww";
    $str=chn_str_replace(" ","&nbsp;",$str);
    $str=chn_str_replace(chr(13).chr(10),"<br>",$str);
    为什么第二行的走得比实际距离远了?成了:
    wwwwww
              wwwww//明显偏远。
                 wwwwwwwww
      

  4.   

    而上面csdn就没有这个问题,因为是每一航都判断的,我估计是代码的问题。请看看。
      

  5.   

    To evfa(evfa) :不行,你不妨试试。