自定义ubb代码,preg_replace()函数的一些代码
更新时间:2007年03月20日 00:00:00 作者:
function ubb($Text) {
$Text=htmlspecialchars($Text);
$Text=ereg_replace("\r\n","
",$Text);
$Text=ereg_replace("\r","
",$Text);
$Text=nl2br($Text);
$Text=preg_replace("/\\t/is"," ",$Text);
$Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","
\\1
",$Text);$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","
\\1
",$Text);$Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","
\\1
",$Text);$Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","
\\1
",$Text);$Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","
\\1
",$Text);$Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","
\\1
",$Text);$Text=preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","\\1",$Text);
$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","http://\\1",$Text);
$Text=preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","\\2",$Text);
$Text=preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","\\2",$Text);
$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","",$Text);
$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","\\2",$Text);
$Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","\\2",$Text);
$Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","\\1",$Text);
$Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","\\1",$Text);
$Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","
\\1",$Text);
$Text=preg_replace("/\[email\](.+?)\[\/email\]/is","\\1",$Text);
$Text=preg_replace("/\[i\](.+?)\[\/i\]/is","\\1",$Text);
$Text=preg_replace("/\[b\](.+?)\[\/b\]/is","\\1",$Text);
$Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","
quote:", $Text);
\\1
$Text=preg_replace("/\[code\](.+?)\[\/code\]/is","
code:", $Text);
\\1
$Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","
--------------------------
\\1
--------------------------
return $Text;
}
function str($msg){
global $admin;
if(!$admin[html]) $msg=htmlspecialchars($msg);
if($admin[ubb]) $msg=ubb($msg);
$msg=nl2br($msg); #处理message
$msg= str_replace("\n","",$msg); #处理message
$msg= str_replace("\r","",$msg); #处理message
return $msg;
}
function error($msg){
global $admin;
?>
中的
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","
\\1
",$Text);里面的 ("/\[h2](.+?)\[\/h2]/is","
\\1
",$text)/\[h2](.+?)\[\/h2]/is 转化成
\\1
/\[h2](.+?)\[\/h2]/is 里面的 这些"/\(.+?)\ "之类的符号是怎么看的?是什么意思?
______________________________________________________________________________________________
\是转意,\本身是特殊符号,如果要作为普通字符就要用\来转意,就是说\\表示()也是特殊符号,所以要用\转意
相关文章
正则限制文本输入...2006-07-07
本文给大家分享一段有关java使用正则表达式对注册页面进行验证的代码,代码比较简单,非常不错,感兴趣的朋友一起学习吧2016-09-09
在使用正则表达式时,有时我们需要捕获的内容前后必须是特定内容,但又不捕获这些特定内容的时候,零宽断言就起到作用了2016-10-10
本篇文章是小编日常整理有关js常用的正则表达式,比较全面,对大家学习javascript正则表达式非常有用,需要的朋友一起学习吧2015-09-09
正则获取匹配的结果,使用match 获取匹配结果数组但又不能获取到子表达式匹配结果2011-06-06
regular expressions(正则表达式,以下用re称呼)对小弟来说一直都是神密的地带,看到一些网络上的大大,简单用re就决解了 某些文字的问题2008-09-09
PHP有个去除HTML标签的函数strip_tags,不过对于某些特殊符号不好使,下面这个函数的功能非常强大,同时用户还可以根据自己的需要进行正则替换.2010-05-05
这篇文章主要介绍了正则表达式环视概念与用法,具体分析了环视的概念、分类、使用方法及相关注意事项,需要的朋友可以参考下2017-06-06
这篇文章主要介绍了最新版网址替换正则表达式,本文给出了最新网址正则表达式和示例替换文本,需要的朋友可以参考下2015-04-04
最新评论