2012-03-28 22 views
1

我允許用戶從我的網站發表評論,直接通過API使用twitter。我使用與twitter相同的字符計數器。我允許用戶輸入140個字符,並且隨着用戶開始輸入,我正在減少字符數。我也允許用戶輸入超過140個字符,但如果計數超過140個字符,他不能提交註釋。處理twitter帖子的字符數,其中包括URL

以上所有功能工作正常。當用戶輸入任何URL時,問題就會出現在圖片中。 http://www.google.com

如果您在twitter中鍵入「http://www.google.com」,它會將其計爲24個字符並顯示剩餘116個字符。

我該如何處理?如果我允許用​​戶輸入http://www.google.com以及更多119個字符,那麼我不能將它發佈到twiiter。它正在返回以下錯誤消息 -

REST Response Error: simplexml_load_string() [<a href='function.simplexml- load-string'>function.simplexml-load-string</a>]:^

Twitter如何計算URL的字符?

我使用下面的類字符計數器 -

http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas我已經cusomized如下 -

(function($) { 

$.fn.charCount = function(options){ 

    // default configuration properties 
    var defaults = {  
     allowed: 140,  
     warning: 25, 
     css: 'counter', 
     counterElement: 'span', 
     cssWarning: 'warning', 
     cssExceeded: 'exceeded', 
     counterText: '' 
    }; 

    var options = $.extend(defaults, options); 

    function calculate(obj){ 
     var count = $(obj).val().length; 
     var strButton = ""; 
     if(count >= 1){ 
      strButton = "1"; 
      $('#fcButtonsAct').show(); 
      $('#fcButtonsDis').hide(); 
     }else{ 
      $('#fcButtonsAct').hide(); 
      $('#fcButtonsDis').hide(); 
     } 
     var myObj = $('#myCharCounter'); 

     var available = options.allowed - count; 
     if(available <= options.warning && available >= 0){ 
      $(myObj).addClass(options.cssWarning); 
     } else { 
      $(myObj).removeClass(options.cssWarning); 
     } 
     if(available < 0){ 
      strButton = "1"; 
      $(myObj).addClass(options.cssExceeded); 
      $('#fcButtonsAct').hide(); 
      $('#fcButtonsDis').show(); 
     } else { 
      $(myObj).removeClass(options.cssExceeded); 
     } 

     $(myObj).html('<div style="float:right;line-height:28px;"><i>' + available + ' </i></div>'); 
    }; 

    this.each(function() { 
     calculate(this); 
     $(this).keyup(function(){calculate(this)}); 
     $(this).change(function(){calculate(this)}); 
    }); 

}; 

})(jQuery); 

,並通過調用下面的函數

$("#txtuserstatus").charCount({ 
     allowed: 140, 
     warning: 10, 
     counterText: '', 
     counterElement: 'div' 
}); 

由於得到做到了提前。

+0

Java有沒有這個實現的機會? – 2013-11-30 13:47:00

回答

相關問題