一个ubbcode的函数,速度很快.
函数 一个 速度 很快
2023-06-13 09:13:44 时间
前面见到有人发表
但是速度比较慢,也非常长
这里给出一种
functionubb($str){
$color=Array("red","blue","green");
$str=eregi_replace("\[url\]([a-zA-Z0-9@:%_.~#-\?&]+)\[\/url\]","<ahref=http://\\1>\\1</a>",$str);//url
$str=eregi_replace("\[url=http://([a-zA-Z0-9@:%_.~#-\?&]+)\](.+)\[\/url\]","<ahref=\\1target=_blank>\\2</a>",$str);
$str=eregi_replace("\[url=([a-zA-Z0-9@:%_.~#-\?&]+)\](.+)\[\/url\]","<ahref=http://\\1target=_blank>\\2</a>",$str);
$str=eregi_replace("\[img\]([a-zA-Z0-9@:%_.~#-\?&]+)\[\/img\]","<imgsrc=http://\\1>\\1</img>",$str);//img
$str=eregi_replace("\[h([1-6])\](.+)\[\/h[1-6]\]","<h\\1>\\2</h\\1>",$str);//h1-6
$str=eregi_replace("\[email\]([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})\[\/email\]","<ahref=mailto:\\1>\\1</a>",$str);//email
$str=eregi_replace("\[email=([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})\](.+)\[\/email\]","<ahref=mailto:\\1>\\2</a>",$str);
$str=eregi_replace("\[b\](.+)\[\/b\]","<b>\\1</b>",$str);
$str=eregi_replace("\[i\](.+)\[\/i\]","<i>\\1</i>",$str);
$str=eregi_replace("\[size=(.+)\](.+)\[\/size\]","<fontsize=\\1>\\2</font>",$str);
$str=eregi_replace("\[color=(.+)\](.+)\[\/color\]","<fontcolor=\\1>\\2</font>",$str);
$str=eregi_replace("\[sub\](.+)\[\/sub\]","<sub>\\1</sup>",$str);//下裱
$str=eregi_replace("\[sup\](.+)\[\/sup\]","<sup>\\1</sup>",$str);//上标
for($i=0;$i<=count($color);$i++)$str=eregi_replace("\[".$color[$i]."\](.+)\[\/".$color[$i]."\]","<fontcolor=".$color[$i].">\\1</font>",$str);
$str=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><fontsize="1"face="CourierNew">quote:</font><hr>\\1<hr></blockquote>",$str);
$str=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><fontsize="1"face="TimesNewRoman">code:</font><hrcolor="lightblue"><i>\\1</i><hrcolor="lightblue"></blockquote>",$str);
$str=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<divstyle="text-align:left;color:darkgreen;margin-left:5%"><br><br>--------------------------<br>\\1<br>--------------------------</div>",$str);
return$str;
}
但是速度比较慢,也非常长
这里给出一种
functionubb($str){
$color=Array("red","blue","green");
$str=eregi_replace("\[url\]([a-zA-Z0-9@:%_.~#-\?&]+)\[\/url\]","<ahref=http://\\1>\\1</a>",$str);//url
$str=eregi_replace("\[url=http://([a-zA-Z0-9@:%_.~#-\?&]+)\](.+)\[\/url\]","<ahref=\\1target=_blank>\\2</a>",$str);
$str=eregi_replace("\[url=([a-zA-Z0-9@:%_.~#-\?&]+)\](.+)\[\/url\]","<ahref=http://\\1target=_blank>\\2</a>",$str);
$str=eregi_replace("\[img\]([a-zA-Z0-9@:%_.~#-\?&]+)\[\/img\]","<imgsrc=http://\\1>\\1</img>",$str);//img
$str=eregi_replace("\[h([1-6])\](.+)\[\/h[1-6]\]","<h\\1>\\2</h\\1>",$str);//h1-6
$str=eregi_replace("\[email\]([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})\[\/email\]","<ahref=mailto:\\1>\\1</a>",$str);//email
$str=eregi_replace("\[email=([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})\](.+)\[\/email\]","<ahref=mailto:\\1>\\2</a>",$str);
$str=eregi_replace("\[b\](.+)\[\/b\]","<b>\\1</b>",$str);
$str=eregi_replace("\[i\](.+)\[\/i\]","<i>\\1</i>",$str);
$str=eregi_replace("\[size=(.+)\](.+)\[\/size\]","<fontsize=\\1>\\2</font>",$str);
$str=eregi_replace("\[color=(.+)\](.+)\[\/color\]","<fontcolor=\\1>\\2</font>",$str);
$str=eregi_replace("\[sub\](.+)\[\/sub\]","<sub>\\1</sup>",$str);//下裱
$str=eregi_replace("\[sup\](.+)\[\/sup\]","<sup>\\1</sup>",$str);//上标
for($i=0;$i<=count($color);$i++)$str=eregi_replace("\[".$color[$i]."\](.+)\[\/".$color[$i]."\]","<fontcolor=".$color[$i].">\\1</font>",$str);
$str=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><fontsize="1"face="CourierNew">quote:</font><hr>\\1<hr></blockquote>",$str);
$str=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><fontsize="1"face="TimesNewRoman">code:</font><hrcolor="lightblue"><i>\\1</i><hrcolor="lightblue"></blockquote>",$str);
$str=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<divstyle="text-align:left;color:darkgreen;margin-left:5%"><br><br>--------------------------<br>\\1<br>--------------------------</div>",$str);
return$str;
}
相关文章
- pycharm定义函数无法运行_把一个命令按钮设置成无效
- pycharm中查看某个函数定义_函数的三要素
- mysql截取字符串函数
- Vue 箭头函数
- MySQL和Oracle字符串截取函数用法总结(比较)
- matlab 怎么使用function,Matlab中function函数使用操作方法
- 窗口函数为什么更容易出现性能问题?——一个优化案例
- 用c语言手搓一个600行的类c语言解释器: 给编程初学者的解释器教程(6)- 语义分析:符号表和变量、函数
- ORACLE学习笔记-添加更新数据函数篇
- 创建DOM元素的通用JS函数详解编程语言
- MySQL连接字符串函数:学习如何配置一个安全的连接(mysql连接字符串函数)
- MySQL中的字段函数使用指南(mysql字段函数)
- MySQL中如何使用SUM函数(mysql中sum怎么用)
- MySQL中的MOD函数实现取余运算(mysql中mod函数6)
- 利用Oracle中的取整函数精确控制数据(oracle中的取整函数)
- PHP中一个控制字符串输出的函数
- 一个不用onmouseup的拖动函数
- 计算一个字符串在另一字符串中出现的次数函数
- phparray_push()数组函数:将一个或多个单元压入数组的末尾(入栈)
- SQL语句一个简单的字符串分割函数
- 奉献出一个封装的curl函数便于调用(抓数据专用)
- 一个不错的字符串转码解码函数(自写)
- php获取当月最后一天函数分享