我自己寫的js版參考以下文章做出的
http://www.rupeng.com/innersupesite/index.php/7/viewspace-583
JS版:
function arial_strlen(val, word_length){
var lencounter=0;
var sub_str = 0;
for (var i = 0; i < val.length; i++) {
if(ck_null(word_length) != '-'){
if(Math.ceil(lencounter*2) >= word_length){
return sub_str;
}
}
ch = val.substr(i,1);
var char_050 = ",./;'[]=-/*-!@#$%^&*()_{}:\"<>?1234567890fijlrIt";
asc_ch = ch.charCodeAt();
//if(ord(ch)>128){
if (ch.match(/[^\x00-\xff]/ig) != null){
lencounter++;
}else if(char_050.indexOf(ch) != -1){
lencounter+=0.5;
}else if(asc_ch>=48 && ch<=57){
lencounter+=0.55;
}else if(asc_ch>=97 && asc_ch<=122){//a~z
lencounter+=0.55;
}else if(asc_ch>=65 && asc_ch<=90){//A~Z
lencounter+=0.8;
}else{
lencounter++;
}
sub_str++;
}
return Math.ceil(lencounter*2);
}