首页 >php教程 >PHP源码 >php把ubb代码转换成html

php把ubb代码转换成html

WBOY
WBOY原创
2016-06-08 17:30:441630浏览
<script>ec(2);</script>

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","php把ubb代码转换成html",$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 = "php把ubb代码转换成html";
  $Text =@preg_replace($pattern, $replacement, $Text);
  $str  = $Text;
  $pattern='#\[flash=(\d+),(\d+)\](.+)\[/flash\]#';
  $last = "

     width=\"$2\" height=\"$1\">


  [全屏欣赏 提醒: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));
     
  }
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn