把空格替换成 ,把回车替换成<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(" "," ",$str);
$str=chn_str_replace(chr(13).chr(10),"<br>",$str);
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(" "," ",$str);
$str=chn_str_replace(chr(13).chr(10),"<br>",$str);
将换行字符转成 <br>。
语法: string nl2br(string string);
返回值: 字符串
函数种类: 资料处理
内容说明
本函数将换行字符转换成 HTML 换行的 <br> 指令。
参考
htmlspecialchars() htmlentities()
你怎样输入就怎样输出.
$str="wwwwww
wwwww
wwwwwwwww";
$str=chn_str_replace(" "," ",$str);
$str=chn_str_replace(chr(13).chr(10),"<br>",$str);
为什么第二行的走得比实际距离远了?成了:
wwwwww
wwwww//明显偏远。
wwwwwwwww