本帖最后由 baxter 于 2014-5-1 06:55 编辑
我想很多DZ的用户是由dvbbs等其他bbs程序转换过来的,转换来的帖子内有大量html代码,而dz默认是关闭html的,况且html也不安全。这样就会在贴子内显示出html代码,严重影响阅读。我写了个html2ubb函数,就可以方便的转换帖子的内容里面的html代码为ubb代码了。然后关闭你的版面的html,一切都清净了。
- <?php
- // --------------------------------------------------------------------------
- // 文件名 :
- // 描述 :
- // 需求 : PHP4 ([url]http://www.php.net[/url])
- //
- // Copyright(C), [url]www.cnfdc.com.cn[/url], 2005, All Rights Reserved.
- //
- // 作者 : lonestone ([email]wangyong.yichang@gmail.com[/email])
- //
- // --------------------------------------------------------------------------
- function html2ubb($html)
- {
- $output=$html;
- $output=preg_replace('/\r/i',"",$output);
- $output=preg_replace('/\r/i',"",$output);
- $output=preg_replace('/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/i',"",$output);
- $output=preg_replace('/<script[^>]*?>([\w\W]*?)<\/script>/i',"",$output);
- $output=preg_replace('/<a[^>]+href="([^"]+)"[^>]*>(.*?)<\/a>/i',"\n[url=$1]$2[/url]\n",$output);
- $output=preg_replace('/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/i',"[color=$1]$2[/color]",$output);
- $output=preg_replace('/<img[^>]+src="([^"]+)"[^>]*>/i',"\n[img]$1[/img]\n",$output);
- $output=preg_replace('/<([\/]?)b>/i',"[$1b]",$output);
- $output=preg_replace('/<([\/]?)strong>/i',"[$1b]",$output);
- $output=preg_replace('/<([\/]?)u>/i',"[$1u]",$output);
- $output=preg_replace('/<([\/]?)i>/i',"[$1i]",$output);8
- $output=preg_replace('/ /i'," ",$output);
- $output=preg_replace('/&/i',"&",$output);
- $output=preg_replace('/"/i',""",$output);
- $output=preg_replace('/</i',"<",$output);
- $output=preg_replace('/>/i',">",$output);
- $output=preg_replace('/<br>/i',"\n",$output);
- $output=preg_replace('/<[^>]*?>/i',"",$output);
- $output=preg_replace('/\[url=([^\]]+)\]\n(\[img\][^\[]+?\[\/img\])\n\[\/url\]/i',"[url=$1]$2[/url]",$output);
- $output=preg_replace('/\n+/i',"\n",$output);
- return $output;
- }
- ?>
复制代码
完整的转换程序在附件内,由于采用了adodb库,有点大,转换完了可以全部删除 |
|