作者:mobiledu2502918317 | 来源:互联网 | 2018-07-17 07:10
ec(2);php把ubb代码转换成htmlfunction ubb($Text) { $Texthtmlspecialchars($Text); $Textstripslashes($Text); $Textereg_replace("r
php把ubb代码转换成html
function ubb($Text)
{
$Text=htmlspecialchars($Text);
$Text=stripslashes($Text);
$Text=ereg_replace("\r\n","
",$Text);
$Text=ereg_replace("\r","
",$Text);
$Text=nl2br($Text);
$Text=preg_replace("/\\t/is"," ",$Text);
$Text=ereg_replace(" "," ",$Text);
$Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","
\\1
",$Text);
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","
\\1
",$Text);
$Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","
\\1
",$Text);
$Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","
\\1
",$Text);
$Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","
\\1
",$Text);
$Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","
\\1
",$Text);
$Text=preg_replace("/\[center\](.+?)\[\/center\]/is","
\\1",$Text);
$Text=preg_replace("/\[big\](.+?)\[\/big\]/is","
\\1",$Text);
$Text=preg_replace("/\[small\](.+?)\[\/small\]/is","
\\1",$Text);
$Text=preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","
\\1",$Text);
$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","
http://\\1",$Text);
$Text=preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","
\\2",$Text);
$Text=preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","
\\2",$Text);
$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","
",$Text);
$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","
\\2",$Text);
$Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","
\\2",$Text);
$Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","
\\1",$Text);
$Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","
\\1",$Text);
$Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","
\\1
",$Text);
$Text=preg_replace("/\[email\](.+?)\[\/email\]/is","
\\1",$Text);
$Text=preg_replace("/\[i\](.+?)\[\/i\]/is","
\\1",$Text);
$Text=preg_replace("/\[b\](.+?)\[\/b\]/is","
\\1",$Text);
$Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","
quote:
\\1
", $Text);
$pattern = "/(\[uploadimage\])(\d+),(.*)(\[\/uploadimage\])/U";
$replacement = "
";
$Text =@preg_replace($pattern, $replacement, $Text);
$str = $Text;
$pattern='#\[flash=(\d+),(\d+)\](.+)\[/flash\]#';
$last = "
[全屏欣赏 提醒:Flash中可能包含不安全内容]
";
$Text= preg_replace($pattern, $last, $str);
$mpg ="
";
$Text =preg_replace('#\[mp=(\d+),(\d+)\](.+)\[/mp\]#', $mpg, $Text);
return @iconv('utf-8','gbk',@iconv('gbk','utf-8',$Text));
}