自定义ubb代码,preg_replace()函数的一些代码
2007-03-20 00:00
1471 查看
function ubb($Text) {
$Text=htmlspecialchars($Text);
$Text=ereg_replace("\r\n","<br>",$Text);
$Text=ereg_replace("\r","<br>",$Text);
$Text=nl2br($Text);
$Text=preg_replace("/\\t/is"," ",$Text);
$Text=preg_replace("/\[h1\]https://www.jb51.net/article/(.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text);
$Text=preg_replace("/\[h2\]https://www.jb51.net/article/(.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
$Text=preg_replace("/\[h3\]https://www.jb51.net/article/(.+?)\[\/h3\]/is","<h3>\\1</h3>",$Text);
$Text=preg_replace("/\[h4\]https://www.jb51.net/article/(.+?)\[\/h4\]/is","<h4>\\1</h4>",$Text);
$Text=preg_replace("/\[h5\]https://www.jb51.net/article/(.+?)\[\/h5\]/is","<h5>\\1</h5>",$Text);
$Text=preg_replace("/\[h6\]https://www.jb51.net/article/(.+?)\[\/h6\]/is","<h6>\\1</h6>",$Text);
$Text=preg_replace("/\[url\]https://www.jb51.net/article/(http:\/\/.+?)\[\/url\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[url\]https://www.jb51.net/article/(.+?)\[\/url\]/is","<a href=\"http://\\1\">http://\\1</a>",$Text);
$Text=preg_replace("/\(.*)\[\/url\]/is","<a href=\\1>\\2</a>",$Text);
$Text=preg_replace("/\[url=https://www.jb51.net/article/(.+?)\](.*)\[\/url\]/is","<a href=http://\\1>\\2</a>",$Text);
$Text=preg_replace("/\[img\]https://www.jb51.net/article/(.+?)\[\/img\]/is","<img src=\\1>",$Text);
$Text=preg_replace("/\[color=https://www.jb51.net/article/(.+?)\]https://www.jb51.net/article/(.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[size=https://www.jb51.net/article/(.+?)\]https://www.jb51.net/article/(.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[sup\]https://www.jb51.net/article/(.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text);
$Text=preg_replace("/\[sub\]https://www.jb51.net/article/(.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text);
$Text=preg_replace("/\[pre\]https://www.jb51.net/article/(.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text);
$Text=preg_replace("/\[email\]https://www.jb51.net/article/(.+?)\[\/email\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[i\]https://www.jb51.net/article/(.+?)\[\/i\]/is","<i>\\1</i>",$Text);
$Text=preg_replace("/\[b\]https://www.jb51.net/article/(.+?)\[\/b\]/is","<b>\\1</b>",$Text);
$Text=preg_replace("/\[quote\]https://www.jb51.net/article/(.+?)\[\/quote\]/is","<blockquote><font size='2' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $Text);
$Text=preg_replace("/\[code\]https://www.jb51.net/article/(.+?)\[\/code\]/is","<blockquote><font size='2' face='Courier New'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>", $Text);
$Text=preg_replace("/\[sig\]https://www.jb51.net/article/(.+?)\[\/sig\]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $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\]https://www.jb51.net/article/(.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
里面的 ("/\[h2]https://www.jb51.net/article/(.+?)\[\/h2]/is","<h2>\\1</h2>",$text)
/\[h2]https://www.jb51.net/article/(.+?)\[\/h2]/is 转化成 <h2>\\1</h2>
/\[h2]https://www.jb51.net/article/(.+?)\[\/h2]/is 里面的 这些"/\https://www.jb51.net/article/(.+?)\ "之类的符号是怎么看的?是什么意思?
______________________________________________________________________________________________
\是转意,\本身是特殊符号,如果要作为普通字符就要用\来转意,就是说\\表示()也是特殊符号,所以要用\转意
eregi_replace()中特殊字符的处理方法
javascript replace()用法详解附实例代码
javascript replace()正则替换实现代码
js replace() 文本替换你所不知的
js中字符替换函数String.replace()使用技巧
PHP preg_replace() 正则替换所有符合条件的字符串
浅谈jQuery中replace()方法
浅谈javascript中replace()方法
浅谈C++中replace()方法
$Text=htmlspecialchars($Text);
$Text=ereg_replace("\r\n","<br>",$Text);
$Text=ereg_replace("\r","<br>",$Text);
$Text=nl2br($Text);
$Text=preg_replace("/\\t/is"," ",$Text);
$Text=preg_replace("/\[h1\]https://www.jb51.net/article/(.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text);
$Text=preg_replace("/\[h2\]https://www.jb51.net/article/(.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
$Text=preg_replace("/\[h3\]https://www.jb51.net/article/(.+?)\[\/h3\]/is","<h3>\\1</h3>",$Text);
$Text=preg_replace("/\[h4\]https://www.jb51.net/article/(.+?)\[\/h4\]/is","<h4>\\1</h4>",$Text);
$Text=preg_replace("/\[h5\]https://www.jb51.net/article/(.+?)\[\/h5\]/is","<h5>\\1</h5>",$Text);
$Text=preg_replace("/\[h6\]https://www.jb51.net/article/(.+?)\[\/h6\]/is","<h6>\\1</h6>",$Text);
$Text=preg_replace("/\[url\]https://www.jb51.net/article/(http:\/\/.+?)\[\/url\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[url\]https://www.jb51.net/article/(.+?)\[\/url\]/is","<a href=\"http://\\1\">http://\\1</a>",$Text);
$Text=preg_replace("/\(.*)\[\/url\]/is","<a href=\\1>\\2</a>",$Text);
$Text=preg_replace("/\[url=https://www.jb51.net/article/(.+?)\](.*)\[\/url\]/is","<a href=http://\\1>\\2</a>",$Text);
$Text=preg_replace("/\[img\]https://www.jb51.net/article/(.+?)\[\/img\]/is","<img src=\\1>",$Text);
$Text=preg_replace("/\[color=https://www.jb51.net/article/(.+?)\]https://www.jb51.net/article/(.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[size=https://www.jb51.net/article/(.+?)\]https://www.jb51.net/article/(.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[sup\]https://www.jb51.net/article/(.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text);
$Text=preg_replace("/\[sub\]https://www.jb51.net/article/(.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text);
$Text=preg_replace("/\[pre\]https://www.jb51.net/article/(.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text);
$Text=preg_replace("/\[email\]https://www.jb51.net/article/(.+?)\[\/email\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[i\]https://www.jb51.net/article/(.+?)\[\/i\]/is","<i>\\1</i>",$Text);
$Text=preg_replace("/\[b\]https://www.jb51.net/article/(.+?)\[\/b\]/is","<b>\\1</b>",$Text);
$Text=preg_replace("/\[quote\]https://www.jb51.net/article/(.+?)\[\/quote\]/is","<blockquote><font size='2' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $Text);
$Text=preg_replace("/\[code\]https://www.jb51.net/article/(.+?)\[\/code\]/is","<blockquote><font size='2' face='Courier New'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>", $Text);
$Text=preg_replace("/\[sig\]https://www.jb51.net/article/(.+?)\[\/sig\]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $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\]https://www.jb51.net/article/(.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
里面的 ("/\[h2]https://www.jb51.net/article/(.+?)\[\/h2]/is","<h2>\\1</h2>",$text)
/\[h2]https://www.jb51.net/article/(.+?)\[\/h2]/is 转化成 <h2>\\1</h2>
/\[h2]https://www.jb51.net/article/(.+?)\[\/h2]/is 里面的 这些"/\https://www.jb51.net/article/(.+?)\ "之类的符号是怎么看的?是什么意思?
______________________________________________________________________________________________
\是转意,\本身是特殊符号,如果要作为普通字符就要用\来转意,就是说\\表示()也是特殊符号,所以要用\转意
您可能感兴趣的文章:
- [url=https://www.geek-share.com/detail/2750324082.html]php正则之函数 preg_replace()参数说明
相关文章推荐
- PHP 文件系统管理函数与 preg_replace() 函数过滤代码
- eregi_replace与preg_replace 函数代码的用法比较
- php正则之函数 preg_replace()参数说明
- GoAhead2.5源代码分析之4-用户管理用到的一些函数(uemf.c misc.c)
- 【代码笔记】对iphone手机进行判断的一些函数
- 第七章 php自定义函数实现代码
- preg_replace()函数。该函数执行正则表达式的搜索和替换。
- 自定义属性之图片切换实例——代码简化、函数合并——JS学习笔记2015-5-30(第43天)
- preg_replace 代码执行原理
- 深入研究PHP中的preg_replace和代码执行
- 使用水晶报表自定义函数进行代码重用
- [2012-4-10]ThinkPHP框架被爆任意代码执行漏洞(preg_replace)
- 当你在VC++6.0编译上面的代码时会提示一些opencv的函数没有被定义,原因是环境没设置好
- 关于如何提取代码成为函数,自己浅薄的一些看法
- 重构代码 —— 函数即变量(Replace temp with Query)
- oracle数据库常用的一些自定义函数
- 微信自定义菜单接口使用的一些函数
- 关于postgresql自定义函数和触发器的一些问题
- php生成随机密码自定义函数代码(简单快速)