Discuz!开发之HTML转Discuz代码(bbcode)函数html2bbcode()
来源:互联网 发布:杨紫 否认整容 知乎 编辑:程序博客网 时间:2024/05/21 17:38
定义文件:\source\function\function_editor.php
函数定义:
function html2bbcode($text) {$text = strip_tags($text, '<table><tr><td><b><strong><i><em><u><a><div><span><p><strike><blockquote><ol><ul><li><font><img><br><br/><h1><h2><h3><h4><h5><h6><script>');if(ismozilla()) {$text = preg_replace("/(?<!<br>|<br \/>|\r)(\r\n|\n|\r)/", ' ', $text);}$pregfind = array("/<script.*>.*<\/script>/siU",'/on(mousewheel|mouseover|click|load|onload|submit|focus|blur)="[^"]*"/i',"/(\r\n|\n|\r)/","/<table([^>]*(width|background|background-color|bgcolor)[^>]*)>/siUe","/<table.*>/siU","/<tr.*>/siU","/<td>/i","/<td(.+)>/siUe","/<\/td>/i","/<\/tr>/i","/<\/table>/i",'/<h([0-9]+)[^>]*>/siUe','/<\/h([0-9]+)>/siU',"/<img[^>]+smilieid=\"(\d+)\".*>/esiU","/<img([^>]*src[^>]*)>/eiU","/<a\s+?name=.+?\".\">(.+?)<\/a>/is","/<br.*>/siU","/<span\s+?style=\"float:\s+(left|right);\">(.+?)<\/span>/is",);$pregreplace = array('','','',"tabletag('\\1')",'[table]','[tr]','[td]',"tdtag('\\1')",'[/td]','[/tr]','[/table]',"\"[size=\".(7 - \\1).\"]\"","[/size]\n\n","smileycode('\\1')","imgtag('\\1')",'\1',"\n","[float=\\1]\\2[/float]",);$text = preg_replace($pregfind, $pregreplace, $text);$text = recursion('b', $text, 'simpletag', 'b');$text = recursion('strong', $text, 'simpletag', 'b');$text = recursion('i', $text, 'simpletag', 'i');$text = recursion('em', $text, 'simpletag', 'i');$text = recursion('u', $text, 'simpletag', 'u');$text = recursion('a', $text, 'atag');$text = recursion('font', $text, 'fonttag');$text = recursion('blockquote', $text, 'simpletag', 'indent');$text = recursion('ol', $text, 'listtag');$text = recursion('ul', $text, 'listtag');$text = recursion('div', $text, 'divtag');$text = recursion('span', $text, 'spantag');$text = recursion('p', $text, 'ptag');$pregfind = array("/(?<!\r|\n|^)\[(\/list|list|\*)\]/", "/<li>(.*)((?=<li>)|<\/li>)/iU", "/<p.*>/iU", "/<p><\/p>/i", "/(<a>|<\/a>|<\/li>)/is", "/<\/?(A|LI|FONT|DIV|SPAN)>/siU", "/\[url[^\]]*\]\[\/url\]/i", "/\[url=javascript:[^\]]*\](.+?)\[\/url\]/is");$pregreplace = array("\n[\\1]", "\\1\n", "\n", '', '', '', '', "\\1");$text = preg_replace($pregfind, $pregreplace, $text);$strfind = array(' ', '<', '>', '&');$strreplace = array(' ', '<', '>', '&');$text = str_replace($strfind, $strreplace, $text);return dhtmlspecialchars(trim($text));}使用举例:
require_once libfile('function/editor');$html='<strong>这里是加粗文本</strong>';$bbcode = html2bbcode($html);echo $bbcode;//输出:[b]这里是加粗文本[/b]
0 0
- Discuz!开发之HTML转Discuz代码(bbcode)函数html2bbcode()
- Discuz开发之function_core常用函数解析
- Discuz函数之daddslashes
- DISCUZ是什么?谁开发了DISCUZ? 【转】
- Discuz!开发之发帖回帖@会员功能代码解析
- Discuz!开发之文件加载路径函数libfile()介绍
- Discuz!开发之字符串处理函数dhtmlspecialchars介绍
- Discuz!开发之js弹出框函数showDialog介绍
- Discuz!开发之私信、提醒信息发送函数sendpm()解析
- Discuz!开发之判断蜘蛛(机器人)访问函数checkrobot()介绍
- Discuz!开发之核心加密解密函数authcode()介绍
- Discuz!开发之时间处理函数dgmdate()详解
- Discuz!开发之网站后台表单生成函数showsetting()详情
- Discuz!开发之网站后台消息提醒函数cpmsg()介绍
- Discuz!开发之后台面包屑导航生成函数shownav()介绍
- Discuz!开发之认识Discuz!的MVC结构
- Discuz
- discuz
- [ios/oc] UIWebView 首次非主线程调用导致crash
- Thread->sleep、wait、join使用
- 自定义EXCEL导出功能
- 每日一题 No.38 AI贪吃蛇(三)
- 《FreeSWITCH: VoIP实战》:PSTN 与 PBX 业务
- Discuz!开发之HTML转Discuz代码(bbcode)函数html2bbcode()
- 软件测试面试(一)
- 哈希表及处理冲突的方法
- 深度残差网络<1>
- 通过位运算来实现基本四则运算
- Qt5.7+Opencv2.4.9人脸识别(五)人脸识别
- Greeting! Everyone
- c++标准输出
- 关于weakref的用法