用C#把HTML内容转为UBB的方法

         ///   <summary>
        
///  把HTML内容转为UBB代码
        
///   </summary>
        
///   <param name="_Html"></param>
        
///   <returns></returns>
         private   string  DoHtmlToUBB( string  _Html)
        {           
            
            _Html 
=  Regex.Replace(_Html,  " <br[^>]*> " " \n " );
            _Html 
=  Regex.Replace(_Html,  @" <p[^>\/]*\/> " " \n " );
            _Html 
=  Regex.Replace(_Html,  " \\son[\\w]{3,16}\\s?=\\s*([\'\ " ]). +? \\ 1 " "" );
            _Html  =  Regex.Replace(_Html,  " <hr[^>]*> " " [hr] " );

            _Html 
=  Regex.Replace(_Html,  " <(\\/)?blockquote([^>]*)> " " [$1blockquote] " );
            _Html 
=  Regex.Replace(_Html,  " <img[^>]*smile=\ " (\\d + )\ " [^>]*> " " '[s:$1] " );
            _Html 
=  Regex.Replace(_Html,  " <img[^>]*src=[\'\ " \\s] * ([ ^ \\s\ ' \"]+)[^>]*>", "");
            _Html  =  Regex.Replace(_Html,  " <a[^>]*href=[\'\ " \\s] * ([ ^ \\s\ ' \"]*)[^>]*>(.+?)<\\/a>", "[url=$1]$2[/url]");

            _Html 
=  Regex.Replace(_Html,  " <[^>]*?> " "" );
            _Html 
=  Regex.Replace(_Html,  " &amp; " " & " );
            _Html 
=  Regex.Replace(_Html,  " &nbsp; " "   " );
            _Html 
=  Regex.Replace(_Html,  " &lt; " " < " );
            _Html 
=  Regex.Replace(_Html,  " &gt; " " > " );

            
return  _Html;
        }

你可能感兴趣的:(html)