计算2个拼音的相似度,百度示例是JAVA版本的 我修改成PHP 版本的。
原文是在我的博客,欢迎大家访问 点击打开链接(点这里)
使用方法如 getEditDistance(“zhang1,san1”, “zhang1,shan1”);
(JAVA版本)
public static int getEditDistance(String s, String t) {
int d[][]; // matrix
int n; // length of s
int m; // length of t
int i; // iterates through s
int j; // iterates through t
char s_i; // ith character of s
char t_j; // jth character of t
int cost; // cost
// Step 1
n = s.length();