After my working time, I found an interesting open source project named phpjs. Their site said that its an open source project to port PHP functions to JavaScript. By including the library in projects, PHP functions may be used client-side. So we can use PHP functions in client-side using Javascript.
function similar_text(string1,string2){
var l1 = string1.length;
var l2 = string2.length;
var arr1 = string1.split('');
var arr2 = string2.split('');
var similar_txt = 0;
var temp="";
var arr3 = new Array();
var arr_result = new Array();s
for(var i=0; i<=l1-1; i++){
for(var j=0; j<=l2-1; j++){
temp = arr1[i]+arr2[j];
if(arr1[i]==arr2[j]){
arr3.push(temp);
}
}
}
label:for(var k=0; k<arr3.length;k++ ) {
for(var l=0; l<arr_result.length;l++ ) {
if(arr_result[l]==arr3[k]){
continue label;
}
}
arr_result[arr_result.length] = arr3[k];
}
//console.log(arr_result);
similar_txt=arr_result.length;
return similar_txt;
}
Actually, the phpjs site owner has not approved my function above. I hope that he will approve and add it as one of phpjs functions.
However you don't have to worry about it. I've tested it with some various strings and compare the result with PHP similar_text functions. All test results are exactly the same.
Meanwhile, I will try to look another PHP functions that have not been ported to Javascript yet. Hope that I can contribute more to that project since it's really interesting.
Please notice that the function above has been revised in this post : PHP similar_text function in Javascript #2