caoyinghui

          UBB轉HTML和HTML轉UBB

          function htmlToubb(h,u){
          	str = pattern(document.getElementById(h).value);
          	document.getElementById(u).value=str;
          }
          
          function ubbTohtml(u,h){
          	str = up(document.getElementById(u).value);
          	document.getElementById(h).value=str;
          }
          
          function pattern(str){
          	str = str.replace(/<br[^>]*>/ig,'\n');
          	str = str.replace(/<p[^>\/]*\/>/ig,'\n');
          	str = str.replace(/\son[\w]{3,16}\s?=\s*([\'\"]).+?\1/ig,'');
          	str = str.replace(/<hr[^>]*>/ig,'[hr]');
          	str = str.replace(/<(sub|sup|u|strike|b|i|pre)>/ig,'[$1]');
          	str = str.replace(/<\/(sub|sup|u|strike|b|i|pre)>/ig,'[/$1]');
          	str = str.replace(/<(\/)?strong>/ig,'[$1b]');
          	str = str.replace(/<(\/)?em>/ig,'[$1i]');
          	str = str.replace(/<(\/)?blockquote([^>]*)>/ig,'[$1blockquote]');
          	str = str.replace(/<img[^>]*smile=\"(\d+)\"[^>]*>/ig,'[s:$1]');
          	str = str.replace(/<img[^>]*src=[\'\"\s]*([^\s\'\"]+)[^>]*>/ig,'[img]'+'$1'+'[/img]');
          	str = str.replace(/<a[^>]*href=[\'\"\s]*([^\s\'\"]*)[^>]*>(.+?)<\/a>/ig,'[url=$1]'+'$2'+'[/url]');
          	str = str.replace(/<[^>]*?>/ig, '');
          	str = str.replace(/&amp;/ig, '&');
          	str = str.replace(/&lt;/ig, '<');
          	str = str.replace(/&gt;/ig, '>');
          	return str;
          }
          
          function up(str){
          	str = str.replace(/</ig,'&lt;');
          	str = str.replace(/>/ig,'&gt;');
          	str = str.replace(/\n/ig,'<br />');
          	str = str.replace(/\[code\](.+?)\[\/code\]/ig, function($1, $2) {return phpcode($2);});
          	str = str.replace(/\[hr\]/ig,'<hr />');
          	str = str.replace(/\[\/(size|color|font|backcolor)\]/ig,'</font>');
          	str = str.replace(/\[(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'<$1>');
          	str = str.replace(/\[\/(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'</$1>');
          	str = str.replace(/\[\/align\]/ig,'</p>');
          	str = str.replace(/\[(\/)?h([1-6])\]/ig,'<$1h$2>');
          	str = str.replace(/\[align=(left|center|right|justify)\]/ig,'<p align="$1">');
          	str = str.replace(/\[size=(\d+?)\]/ig,'<font size="$1">');
          	str = str.replace(/\[color=([^\[\<]+?)\]/ig, '<font color="$1">');
          	str = str.replace(/\[backcolor=([^\[\<]+?)\]/ig, '<font style="background-color:$1">');
          	str = str.replace(/\[font=([^\[\<]+?)\]/ig, '<font face="$1">');
          	str = str.replace(/\[list=(a|A|1)\](.+?)\[\/list\]/ig,'<ol type="$1">$2</ol>');
          	str = str.replace(/\[(\/)?list\]/ig,'<$1ul>');
          	str = str.replace(/\[s:(\d+)\]/ig,function($1,$2){ return smilepath($2);});
          	str = str.replace(/\[img\]([^\[]*)\[\/img\]/ig,'<img src="$1" border="0" />');
          	str = str.replace(/\[url=([^\]]+)\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$2'+'</a>');
          	str = str.replace(/\[url\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$1'+'</a>');
          	return str;
          }
          
          ?

          已有 0 人發表留言,猛擊->>這里<<-參與討論


          ITeye推薦



          posted on 2011-08-31 14:09 shine_panda 閱讀(695) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2011年8月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 沁水县| 武宁县| 招远市| 湟中县| 开远市| 木兰县| 耿马| 晋江市| 通江县| 玉田县| 郴州市| 嘉定区| 法库县| 建始县| 咸宁市| 隆回县| 濮阳市| 鄢陵县| 克什克腾旗| 金沙县| 崇信县| 牟定县| 武汉市| 丰镇市| 邢台市| 旬邑县| 无为县| 黎城县| 渝北区| 平顺县| 岳池县| 太仆寺旗| 彭水| 中宁县| 大洼县| 枞阳县| 桃江县| 南丹县| 隆林| 宣武区| 和硕县|