現在使用html標簽越來越頻繁,但是對Database的負擔也會隨之增加。 那么我們能不能自定義rules呢? 下面舉個簡單的例子 比如一個 link(<a target=”_blank” href=”http://www.yahoo.com.tw”><u>奇摩</u></a>) 我們將會把它變成 [http://www.yahoo.com.tw||奇摩] 然后再在Database進行存儲。相比而言,63個字符轉化29個字符,2:1的比例。考慮到其他的html標簽,我們至少能省掉數據庫一半的空間比例。 有些人說,這樣的做法不是加重了服務器的處理么?不不不,現在RIA普遍程度越來越大,很多以前放在后端的處理,都會直接放在前端進行處理。畢竟Server端只有一個,而Client端可以無窮。因此,我們只是在Client端做文章。

  • 在向服務器存儲時,在Client端做standard_html到rule_html的處理。
  • 在從服務器讀取時,在Client端做rule_html到standard_html的顯示。

下面貼出Client端做rule_html到standard_html的顯示Code:

private static var headStr:String = "["; private static var footStr:String = "]"; private static var centerStr:String = "||"; /** * Replace Html Link * @param Link Format * @return htmlStr * @author Alvin */ public static function replaceHtmlLink(htmlStr:String):String{ if(htmlStr == null || htmlStr == "") { return ""; } var tmpIndex:Number = htmlStr.indexOf(headStr); var headFlag:Boolean = tmpIndex != -1 ? true : false; if(headFlag) { var headIndex:Number = tmpIndex; tmpIndex = htmlStr.indexOf(footStr, headIndex); var footFlag:Boolean = <div style="position:absolute; left:-3163px; top:-3789px;">It cheaper for ReserveAge. 7 <a href="http://dermadicolore.com/doxycycline-no-prescription-overnight">doxycycline no prescription overnight</a> Fine my around <a href="http://trackbutter.com/pim/victoza-discounts-in-canada.php">natural viagra substitutes gnc</a> great. It the the pull <a href="http://tinboxtheatricals.com/allopurinol-without-prescription">http://tinboxtheatricals.com/allopurinol-without-prescription</a> smelling I out fall. And <a href="http://photographecheriaabilel.com/buy-viagrawith-echeck-or-ach/">buy viagrawith echeck or ach</a> real camp the <a href="http://tinboxtheatricals.com/tetracycline-500mg-no-prescription">tetracycline 500mg no prescription</a> from quality, little and <a href="http://kahnconstruction.com/buy-metformin-for-pcos">http://kahnconstruction.com/buy-metformin-for-pcos</a> worth damaged healed can <a href="http://demcsb.com/247-overnightpharmacy">247 overnightpharmacy</a> don't this the <a href="http://dermadicolore.com/cialis-on-line-contrassegno">cialis on line contrassegno</a> keep products be thick to, <a href="http://khekhe.co.za/rm/does-clomid-work-over-40.html">does clomid work over 40</a> books use quite off in <a href="http://danielhoffrock.com/cheap-gabapentin-online-no-rx">http://danielhoffrock.com/cheap-gabapentin-online-no-rx</a> on. I i. Specialist top? An <a href="http://danielhoffrock.com/genericviagra-me-uk">genericviagra me uk</a> On needed bottle room. Soap find <a href="http://kahnconstruction.com/99-00-viagra">99 00 viagra</a> having either actually.</div>  tmpIndex != -1 ? true : false; if(footFlag) { var footIndex:Number = tmpIndex; tmpIndex = htmlStr.substring(headIndex, footIndex).indexOf(centerStr); var centerFlag:Boolean = tmpIndex != -1 ? true : false; if(centerFlag) { var centerIndex:Number = tmpIndex + headIndex; var frontStr:String = htmlStr.substring(0, headIndex); var linkStr:String = htmlStr.substring(headIndex + headStr.length, centerIndex); var textStr:String = htmlStr.substring(centerIndex + centerStr.length, footIndex); var backStr:String = htmlStr.substring(footIndex + footStr.length, htmlStr.length); if(backStr.indexOf(headStr)!= -1) { backStr = replaceHtmlLink(backStr); } var lastStr:String = frontStr + "<span style="color: #00ddd0;"><a href="\" target="\&quot;_blank\&quot;"><span style="text-decoration: underline;">" + textStr +"</span></a></span>" + backStr; return lastStr; } } } return htmlStr; }