php正则表达式替换ubb,自定义ubb代码,preg_replace()函数的一些代码

自定义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:
\\1
", $Text);

$Text=preg_replace("/\[code\](.+?)\[\/code\]/is","

code:
\\1
", $Text);

$Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","


--------------------------
\\1
--------------------------
", $Text);

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  里面的 这些"/\(.+?)\ "之类的符号是怎么看的?是什么意思?

______________________________________________________________________________________________

\是转意,\本身是特殊符号,如果要作为普通字符就要用\来转意,就是说\\表示()也是特殊符号,所以要用\转意

相关文章

1a1b05c64693fbf380aa1344a7812747.png

正则限制文本输入...2006-07-07

4f55910a645b073bc4fc65dc10dc14bd.png

本文给大家分享一段有关java使用正则表达式对注册页面进行验证的代码,代码比较简单,非常不错,感兴趣的朋友一起学习吧2016-09-09

4f96a78db829b1556ff16de21e013c7a.png

在使用正则表达式时,有时我们需要捕获的内容前后必须是特定内容,但又不捕获这些特定内容的时候,零宽断言就起到作用了2016-10-10

8cc1031babc6aff2319f1c6af8544aa0.png

本篇文章是小编日常整理有关js常用的正则表达式,比较全面,对大家学习javascript正则表达式非常有用,需要的朋友一起学习吧2015-09-09

0c932a99bb7b6f23c937db507070cc7b.png

正则获取匹配的结果,使用match 获取匹配结果数组但又不能获取到子表达式匹配结果2011-06-06

cca732bf65a93ed2ec0ac80c638460fe.png

regular expressions(正则表达式,以下用re称呼)对小弟来说一直都是神密的地带,看到一些网络上的大大,简单用re就决解了 某些文字的问题2008-09-09

2d9f31f2af7b675a3d153d2b7f1035a7.png

PHP有个去除HTML标签的函数strip_tags,不过对于某些特殊符号不好使,下面这个函数的功能非常强大,同时用户还可以根据自己的需要进行正则替换.2010-05-05

b452cee8ec5cd9e58ab98eba17281e59.png

这篇文章主要介绍了正则表达式环视概念与用法,具体分析了环视的概念、分类、使用方法及相关注意事项,需要的朋友可以参考下2017-06-06

f4838ec7e2d4da28e0b57d4e852dadd4.png

这篇文章主要介绍了最新版网址替换正则表达式,本文给出了最新网址正则表达式和示例替换文本,需要的朋友可以参考下2015-04-04

最新评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值