textarea空格问题,进者有分 替换...s = replace(s,space(1)," ") 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $Text=ereg_replace(" "," ",$Text);$Text//是你的textarea 读出来时,加上htmlspecialchars(变量名)就可以了 呵呵,挺热闹啊,那大家看看这个函数<?function ubb($tmpmsg) {// $tmpmsg =str_replace('<','<',$tmpmsg);// $tmpmsg =str_replace('>','>',$tmpmsg); $tmpmsg=htmlspecialchars($tmpmsg); $tmpmsg=nl2br($tmpmsg); //$tmpmsg =str_replace('',' ',$tmpmsg); $tmpmsg =str_replace('&','&',$tmpmsg); $tmpmsg =str_replace("","<u>",$tmpmsg); $tmpmsg =str_replace("","</u>",$tmpmsg); $tmpmsg =str_replace("","<b>",$tmpmsg); $tmpmsg =str_replace("","</b>",$tmpmsg); $tmpmsg =str_replace("","<i>",$tmpmsg); $tmpmsg =str_replace("","</i>",$tmpmsg); $tmpmsg =str_replace("[br]","<br>",$tmpmsg); $tmpmsg =str_replace("[list]","<ul>",$tmpmsg); $tmpmsg =str_replace("[/list]","</ul>",$tmpmsg); $tmpmsg =str_replace("[olist]","<ol>",$tmpmsg); $tmpmsg =str_replace("[/olist]","</ol>",$tmpmsg); $tmpmsg =str_replace("[*]","<li>",$tmpmsg); $tmpmsg =str_replace("[hr]","<hr width=40% align=left>",$tmpmsg); $tmpmsg =str_replace("[sup]","<sup>",$tmpmsg); $tmpmsg =str_replace("[/sup]","</sup>",$tmpmsg); $tmpmsg =str_replace('[url="','[url="',$tmpmsg); $tmpmsg =str_replace('"]','"]',$tmpmsg); $pattern = array( "/\[font=([^\[]*)\](.+?)\[\/font\]/is", "/\[color=([#0-9a-z]{1,10})\](.+?)\[\/color\]/is", "/\[email=([^\[]*)\](.+?)\[\/email\]/is", "/\[email\]([^\[]*)\[\/email\]/is", "/\[url=([^\[]*)\](.+?)\[\/url\]/is", "/\[url\]www\.([^\[]*)\[\/url\]/is", "/\[url\]([^\[]*)\[\/url\]/is", "/\[quote\](.*)\[quote\](.*)\[\/quote](.*)\[\/quote\]/is", "/\[quote\]\s*(.*?)\s*\[\/quote\]/is", "/(\[fly\])(.+?)(\[\/fly\])/is", "/(\[move\])(.+?)(\[\/move\])/is", "/(\[align=)(left|center|right)(\])(.+?)(\[\/align\])/is", "/(\[shadow=)(\S+?)(\,)(.+?)(\,)(.+?)(\])(.+?)(\[\/shadow\])/is", "/(\[glow=)(\S+?)(\,)(.+?)(\,)(.+?)(\])(.+?)(\[\/glow\])/is", "/\[code\](.+?)\[\/code\]/is"); $replacement = array( "<font face=\"\\1\">\\2</font>", "<font color=\"\\1\">\\2</font>", "<a href=\"mailto:\\1\">\\2</a>", "<a href=\"mailto:\\1\">\\1</a>", "<a href=\"\\1\" target=_blank>\\2</a>", "<a href=\"http://www.\\1\" target=_blank>\\1</a>", "<a href=\"\\1\" target=_blank>\\1</a>", "<blockquote><hr noshade><font face=宋体, helvetica>\\1\\2<br>\\3</font><hr noshade></blockquote>", "<font face=$font><blockquote><hr noshade>\\1<hr noshade></blockquote></font>", "<marquee width=90% behavior=alternate scrollamount=3>\\2</marquee>", "<MARQUEE scrollamount=3>\\2</MARQUEE>", "<DIV Align=\\2>\\4</DIV>", "<table width=\\2 style=\"shadow(color=\\4, direction=\\6 ,strength=2)\">\\8</table>", "<table width=\\2 style=\"filter:glow(color=\\4, strength=\\6)\">\\8</table>", "<table border=0 width=95% align=center cellpadding=2 bgcolor=DDDDDF><tr><td><pre><font face='Courier New'>\\1</font></pre></td></tr></table>"); $tmpmsg=preg_replace($pattern,$replacement,$tmpmsg); $tmpmsg = preg_replace("/\[img\]\s*(\S+?)\s*\[\/img\]/is","<img src=\\1 border=0>",$tmpmsg); $tmpmsg = preg_replace("/(\[swf\])\s*(\S+?\.swf)\s*(\[\/swf\])/is","<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=\"\\2\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\"></embed>",$tmpmsg); $tmpmsg = preg_replace("/(\[FLASH=)(\S+?)(\,)(\S+?)(\])(\S+?)(\[\/FLASH\])/is","<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" WIDTH=\\2 HEIGHT=\\4><PARAM NAME=MOVIE VALUE=\\6><PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><EMBED SRC=\\6 WIDTH=\\2 HEIGHT=\\4 PLAY=TRUE LOOP=TRUE QUALITY=HIGH></EMBED></OBJECT>",$tmpmsg); $tmpmsg = eregi_replace("\\[size=([^\\[]*)\\]","<font size=\\1>",$tmpmsg); $tmpmsg = str_replace("[/size]","</font>",$tmpmsg); return $tmpmsg;}?> 然后我从数据库读出数据的时候用这个函数例如: <?include("inc/conn.php");include("inc/function.php");//其中有ubb函数$sql="select id,body from news where id='$id' order by id";$result=mysql_query($sql);if($myrow=mysql_fetch_array($result)) { $id=$myrow["id"]; $body=ubb($myrow["body"]);echo "$body";}?>这样怎么不可以显示空格呢? $body=str_replace(" ", " ", $myrow["body"]); 楼上的方法没有做好。抗议楼上们,你们都说光了,我还说什么?不过你们漏了一点。嘿嘿。 ice_berg16(寻梦的稻草人) 的替换nbsp的方法解决不了问题。因为在html显示里,超过两个nbsp的空格代码就会自动忽略,显示不出来。呵呵。所以还是要替换成全角空格才行。楼主,你上面说显示不出来空格,给你个方法吧:$body=str_replace(" "," ", $myrow["body"]);注意,第一个是两个半角空格,就是常用的空格。第二个是一个全角空格。这样就能工整显示了。 用 htmlspecial($_POST['textareaName']) 取值就OK了 不好意思~~~~~`应该是 htmlspecialchars($_POST['textareaName']) 上面函数中少了chars *^_^* htmlspecialchars这样不行吧?如果有多个空格,就会最多只显示两个的。 [求助]问一个附件上传的判断的问题 如何通过表单提交性别的值?然后传递给服务器?请大家帮着看看,谢谢了 php中操作xml,关于encoding.. 200分,一个php发送邮件的问题 多种语言网站的开发思路。 group by 问题 高分求救!!! 读取页面内容!!!! 虚拟主机支持SMTP,我怎么发邮件? 兄弟们看看我的这个程序!为什么出错! 多个foreach嵌套循环的问题 急!急!!公司网站不能正常登陆,总是出现错误,大家进来看看啊!!在线等。。。。。高分相赠!!! 菜鸟问题:这样怎么不能传参数?
$Text//是你的textarea
<?
function ubb($tmpmsg) {
// $tmpmsg =str_replace('<','<',$tmpmsg);
// $tmpmsg =str_replace('>','>',$tmpmsg);
$tmpmsg=htmlspecialchars($tmpmsg);
$tmpmsg=nl2br($tmpmsg);
//$tmpmsg =str_replace('',' ',$tmpmsg);
$tmpmsg =str_replace('&','&',$tmpmsg);
$tmpmsg =str_replace("","<u>",$tmpmsg);
$tmpmsg =str_replace("","</u>",$tmpmsg);
$tmpmsg =str_replace("","<b>",$tmpmsg);
$tmpmsg =str_replace("","</b>",$tmpmsg);
$tmpmsg =str_replace("","<i>",$tmpmsg);
$tmpmsg =str_replace("","</i>",$tmpmsg);
$tmpmsg =str_replace("[br]","<br>",$tmpmsg);
$tmpmsg =str_replace("[list]","<ul>",$tmpmsg);
$tmpmsg =str_replace("[/list]","</ul>",$tmpmsg);
$tmpmsg =str_replace("[olist]","<ol>",$tmpmsg);
$tmpmsg =str_replace("[/olist]","</ol>",$tmpmsg);
$tmpmsg =str_replace("[*]","<li>",$tmpmsg);
$tmpmsg =str_replace("[hr]","<hr width=40% align=left>",$tmpmsg);
$tmpmsg =str_replace("[sup]","<sup>",$tmpmsg);
$tmpmsg =str_replace("[/sup]","</sup>",$tmpmsg);
$tmpmsg =str_replace('[url="','[url="',$tmpmsg);
$tmpmsg =str_replace('"]','"]',$tmpmsg); $pattern = array(
"/\[font=([^\[]*)\](.+?)\[\/font\]/is",
"/\[color=([#0-9a-z]{1,10})\](.+?)\[\/color\]/is",
"/\[email=([^\[]*)\](.+?)\[\/email\]/is",
"/\[email\]([^\[]*)\[\/email\]/is",
"/\[url=([^\[]*)\](.+?)\[\/url\]/is",
"/\[url\]www\.([^\[]*)\[\/url\]/is",
"/\[url\]([^\[]*)\[\/url\]/is",
"/\[quote\](.*)\[quote\](.*)\[\/quote](.*)\[\/quote\]/is",
"/\[quote\]\s*(.*?)\s*\[\/quote\]/is",
"/(\[fly\])(.+?)(\[\/fly\])/is",
"/(\[move\])(.+?)(\[\/move\])/is",
"/(\[align=)(left|center|right)(\])(.+?)(\[\/align\])/is",
"/(\[shadow=)(\S+?)(\,)(.+?)(\,)(.+?)(\])(.+?)(\[\/shadow\])/is",
"/(\[glow=)(\S+?)(\,)(.+?)(\,)(.+?)(\])(.+?)(\[\/glow\])/is",
"/\[code\](.+?)\[\/code\]/is"); $replacement = array(
"<font face=\"\\1\">\\2</font>",
"<font color=\"\\1\">\\2</font>",
"<a href=\"mailto:\\1\">\\2</a>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"\\1\" target=_blank>\\2</a>",
"<a href=\"http://www.\\1\" target=_blank>\\1</a>",
"<a href=\"\\1\" target=_blank>\\1</a>",
"<blockquote><hr noshade><font face=宋体, helvetica>\\1\\2<br>\\3</font><hr noshade></blockquote>",
"<font face=$font><blockquote><hr noshade>\\1<hr noshade></blockquote></font>",
"<marquee width=90% behavior=alternate scrollamount=3>\\2</marquee>",
"<MARQUEE scrollamount=3>\\2</MARQUEE>",
"<DIV Align=\\2>\\4</DIV>",
"<table width=\\2 style=\"shadow(color=\\4, direction=\\6 ,strength=2)\">\\8</table>",
"<table width=\\2 style=\"filter:glow(color=\\4, strength=\\6)\">\\8</table>",
"<table border=0 width=95% align=center cellpadding=2 bgcolor=DDDDDF><tr><td><pre><font face='Courier New'>\\1</font></pre></td></tr></table>"); $tmpmsg=preg_replace($pattern,$replacement,$tmpmsg); $tmpmsg = preg_replace("/\[img\]\s*(\S+?)\s*\[\/img\]/is","<img src=\\1 border=0>",$tmpmsg); $tmpmsg = preg_replace("/(\[swf\])\s*(\S+?\.swf)\s*(\[\/swf\])/is","<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=\"\\2\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\"></embed>",$tmpmsg);
$tmpmsg = preg_replace("/(\[FLASH=)(\S+?)(\,)(\S+?)(\])(\S+?)(\[\/FLASH\])/is","<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" WIDTH=\\2 HEIGHT=\\4><PARAM NAME=MOVIE VALUE=\\6><PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><EMBED SRC=\\6 WIDTH=\\2 HEIGHT=\\4 PLAY=TRUE LOOP=TRUE QUALITY=HIGH></EMBED></OBJECT>",$tmpmsg);
$tmpmsg = eregi_replace("\\[size=([^\\[]*)\\]","<font size=\\1>",$tmpmsg);
$tmpmsg = str_replace("[/size]","</font>",$tmpmsg); return $tmpmsg;
}
?>
例如:
<?
include("inc/conn.php");
include("inc/function.php");//其中有ubb函数
$sql="select id,body from news where id='$id' order by id";
$result=mysql_query($sql);
if($myrow=mysql_fetch_array($result))
{
$id=$myrow["id"];
$body=ubb($myrow["body"]);
echo "$body";
}
?>
这样怎么不可以显示空格呢?
$body=str_replace(" "," ", $myrow["body"]);注意,第一个是两个半角空格,就是常用的空格。第二个是一个全角空格。这样就能工整显示了。