求CSDN发帖的UBB的“插入源代码”的功能,服务端对这个[code=HTML][/code]之类的是怎么解析的

cuixiping 2008-03-24 04:51:39
求CSDN发帖的UBB的“插入源代码”的功能,服务端对这个
之类的是怎么解析的
...全文
182 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlccomeon 2012-07-24
  • 打赏
  • 举报
回复
[e01]
wlccomeon 2012-07-24
  • 打赏
  • 举报
回复
[f01]
cxteam 2012-03-04
  • 打赏
  • 举报
回复
不知道是怎样实现自动换行的,我试了discuz的会自动加上<br>,不知道如何解决
cxteam 2012-03-04
  • 打赏
  • 举报
回复
/**
+----------------------------------------------------------
* UBB 解析
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
function ubb($Text) {
$Text=trim($Text);
$Text=ereg_replace("\n","<br>",$Text);
$Text=preg_replace("/\\t/is"," ",$Text);
$Text=preg_replace("/\[hr\]/is","<hr>",$Text);
$Text=preg_replace("/\[separator\]/is","<br/>",$Text);
$Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text);
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
$Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","<h3>\\1</h3>",$Text);
$Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","<h4>\\1</h4>",$Text);
$Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","<h5>\\1</h5>",$Text);
$Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","<h6>\\1</h6>",$Text);
$Text=preg_replace("/\[center\](.+?)\[\/center\]/is","<center>\\1</center>",$Text);
//$Text=preg_replace("/\[url=([^\[]*)\](.+?)\[\/url\]/is","<a href=\\1 target='_blank'>\\2</a>",$Text);
$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"\\1\" target='_blank'>\\1</a>",$Text);
$Text=preg_replace("/\[url=(http:\/\/.+?)\](.+?)\[\/url\]/is","<a href='\\1' target='_blank'>\\2</a>",$Text);
$Text=preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is","<a href=\\1>\\2</a>",$Text);
$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1>",$Text);
$Text=preg_replace("/\[img\s(.+?)\](.+?)\[\/img\]/is","<img \\1 src=\\2>",$Text);
$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[colorTxt\](.+?)\[\/colorTxt\]/eis","color_txt('\\1')",$Text);
$Text=preg_replace("/\[style=(.+?)\](.+?)\[\/style\]/is","<div class='\\1'>\\2</div>",$Text);
$Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text);
$Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text);
$Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text);
$Text=preg_replace("/\[emot\](.+?)\[\/emot\]/eis","emot('\\1')",$Text);
$Text=preg_replace("/\[email\](.+?)\[\/email\]/is","<a href='mailto:\\1'>\\1</a>",$Text);
$Text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$Text);
$Text=preg_replace("/\[u\](.+?)\[\/u\]/is","<u>\\1</u>",$Text);
$Text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$Text);
$Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote>引用:<div style='border:1px solid silver;background:#EFFFDF;color:#393939;padding:5px' >\\1</div></blockquote>", $Text);
$Text=preg_replace("/\[code\](.+?)\[\/code\]/eis","highlight_code('\\1')", $Text);
$Text=preg_replace("/\[php\](.+?)\[\/php\]/eis","highlight_code('\\1')", $Text);
$Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $Text);
return $Text;
}
cuixiping 2008-04-02
  • 打赏
  • 举报
回复
还是没有搞懂
siyee 2008-04-02
  • 打赏
  • 举报
回复

UBB解析方法
我想是csdn的开发人员根据遇到这个UBB的符号对字符串进行解析
根据代码的关键字然后设定了字体的显示样式
ITniao 2008-03-26
  • 打赏
  • 举报
回复
replace
cuixiping 2008-03-24
  • 打赏
  • 举报
回复
http://www.actiprosoftware.com/Products/DotNet/ASPNET/CodeHighlighter/pastecode.aspx
可以了,谢谢

不过可惜只能在.Net下使用,不知道有没有ASP下的呢
  • 打赏
  • 举报
回复
高亮显示应该是他自己的写的类!
No_Data_Found 2008-03-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 cuixiping 的回复:]
http://www.actiprosoftware.com/Products/DotNet/ASPNET/CodeHighlighter/pastecode.aspx

我这个页面进去后,选择代码语言的下拉列表框是空的
[/Quote]

多刷新几次
cuixiping 2008-03-24
  • 打赏
  • 举报
回复
http://www.actiprosoftware.com/Products/DotNet/ASPNET/CodeHighlighter/pastecode.aspx

我这个页面进去后,选择代码语言的下拉列表框是空的
No_Data_Found 2008-03-24
  • 打赏
  • 举报
回复
Actipro CodeHighlighter - ASP.NET Control

http://www.actiprosoftware.com/Products/DotNet/ASPNET/CodeHighlighter/pastecode.aspx
No_Data_Found 2008-03-24
  • 打赏
  • 举报
回复
http://www.zeali.net/entry/71
No_Data_Found 2008-03-24
  • 打赏
  • 举报
回复

syntaxhighlighter

http://code.google.com/p/syntaxhighlighter/
njtongfei 2008-03-24
  • 打赏
  • 举报
回复
我想 他应该是根据关键的字 把关键的字加上颜色的
cuixiping 2008-03-24
  • 打赏
  • 举报
回复
普通的UBB解析我知道,我关键是要它解析插入代码的功能
比如
……

……

……

显示出来的时候,把代码段语法高亮。
No_Data_Found 2008-03-24
  • 打赏
  • 举报
回复
如果 你就是想要csdn的 UBB 解析方法 可能只能去找csdn的开发人员了 这个解析是在 后台完成的
No_Data_Found 2008-03-24
  • 打赏
  • 举报
回复
楼主是两个 星星 吗?

http://www.baidu.com/s?wd=ubb%BD%E2%CE%F6&cl=3

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧