PHP的正则替换Discuz!的HTML转为UBB发布替换,芭奇站群软件专用。不错的代码。。
function dzhtml2ubb($strcontent){
$patterns = array (
"/<br[^>]*>/i",
"/<p[^>\/]*\/>/i",
"/<\/p>/i",
"/\son[\w]{3,16}\s?=\s*([\'\"]).+?\1/i",
"/on(load|click|dbclick|mouseover|mousedown|mouseup)=[\'\"\s]*[\'\"\s]/i",
"/<script[^>]*?>([\w\W]*?)<\/script>/i",
"/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/i",
"/<hr[^>]*>/i",
"/<(sub|sup|u|strike|b|i|pre)>/i",
"/<\/(sub|sup|u|strike|b|i|pre)>/i",
"/<(\/)?strong>/i",
"/<(\/)?em>/i",
"/<(\/)?blockquote([^>]*)>/i",
"/<img[^>]*smile=\"(\d+)\"[^>]*>/i",
"/<img[^>]*src=[\'\"\s]*([^\s\'\"]+)[^>]*>/i",
"/<a[^>]*href=[\'\"\s]*([^\s\'\"]*)[^>]*>(.+?)<\/a>/i",
"/<embed[^>]*src=[\'\"\s]*([^\s\'\"]*)[^>]*><\/embed>/i",
"/ /i",
"/"/i",
"/<[^>]*?>/i",
"/&/i",
"/</i",
"/>/i",
"/\[url=([^\]]+)\](\[img\]\1\[\/img\])\[\/url\]/i"
);
$replace = array (
"\n",
"\n",
"\n",
"",
"",
"",
"[color=$1]$2[/color]",
"[hr]",
"[$1]",
"[/$1]",
"[$1b]",
"[$1i]",
"[$1blockquote]",
"[s:$1]",
"[img]$1[/img]",
"[url=$1]$2[/url]",
"[flash=480,400]$1[/flash]",
" ",
"\"",
"",
"&",
"<",
">",
"$2"
);
return preg_replace($patterns, $replace, $strcontent);
}
用法:print dzhtml2ubb($mystr);