午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

分析PHP的similar_text函數(shù)

瀏覽:25日期:2024-02-24 18:37:27

//比較字串,返回兩個(gè)字串第一個(gè)相同字符的區(qū)域static void php_similar_str(const char *txt1, int len1, const char *txt2, int len2, int *pos1, int *pos2, int *max){char *p, *q;char *end1 = (char *) txt1 + len1;char *end2 = (char *) txt2 + len2;int l;*max = 0;//遍歷字串for (p = (char *) txt1; p < end1; p++) { for (q = (char *) txt2; q < end2; q++) { for (l = 0; (p + l < end1) && (q + l < end2) && (p[l] == q[l]); l++); if (l > *max) { //保存相同區(qū)域信息 *max = l; *pos1 = p - txt1; *pos2 = q - txt2; } }}}

//遞歸函數(shù),比較txt1和txt2的相同字符數(shù)量static int php_similar_char(const char *txt1, int len1, const char *txt2, int len2){int sum;int pos1, pos2, max;

php_similar_str(txt1, len1, txt2, len2, &pos1, &pos2, &max);if ((sum = max)) {//這樣寫有什么意義?????!!!!!

//遞歸上次不同部分的前部 if (pos1 && pos2) { sum += php_similar_char(txt1, pos1, txt2, pos2); }

//遞歸上次不同部分的后部 if ((pos1 + max < len1) && (pos2 + max < len2)) { sum += php_similar_char(txt1 + pos1 + max, len1 - pos1 - max, txt2 + pos2 + max, len2 - pos2 - max); }}

//返回本次比較后的相同字符數(shù)量return sum;}

//PHP函數(shù)本身,一堆宏,做了些串轉(zhuǎn)換和返回值換算,主功能由上面兩個(gè)函數(shù)做了。PHP_FUNCTION(similar_text){zval **t1, **t2, **percent;int ac = ZEND_NUM_ARGS();int sim;if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &t1, &t2, &percent) == FAILURE) { WRONG_PARAM_COUNT;}

convert_to_string_ex(t1);convert_to_string_ex(t2);

if (ac > 2) { convert_to_double_ex(percent);}if (Z_STRLEN_PP(t1) + Z_STRLEN_PP(t2) == 0) { if (ac > 2) { Z_DVAL_PP(percent) = 0; }

RETURN_LONG(0);}sim = php_similar_char(Z_STRVAL_PP(t1), Z_STRLEN_PP(t1), Z_STRVAL_PP(t2), Z_STRLEN_PP(t2));

if (ac > 2) { Z_DVAL_PP(percent) = sim * 200.0 / (Z_STRLEN_PP(t1) + Z_STRLEN_PP(t2));}

RETURN_LONG(sim);}

所有看出similar_text是根據(jù)ASCII做比較的,是不考慮詞組問題的。

測試了一下,結(jié)果如下:

int main(int argc, char *argv[]){ char *str1='weican wuxin'; char *str2='wuxin weican'; int pos1,pos2,max; php_similar_str(str1,strlen(str1),str2,strlen(str2),&pos1,&pos2,&max); printf('php_similar_str:%d,%d=%dn',pos1,pos2,max); max=php_similar_char(str1,strlen(str1),str2,strlen(str2)); printf('php_similar_char:%dn',max); system('PAUSE'); return 0;}

php_similar_str:0,6=6php_similar_char:6

char *str1='TCP協(xié)議通訊工作原a理';char *str2='TCPa協(xié)議通訊工作原理';

php_similar_str:3,4=14php_similar_char:19

標(biāo)簽: PHP
主站蜘蛛池模板: 97超级碰 | 久久理伦| 五月婷婷伊人网 | 黑人一级黄色片 | 国产福利91精品一区二区三区 | 亚洲情在线 | 国产高清视频在线播放 | 亚洲图色在线 | 黄色一级片免费 | 久久精品久久久久 | 污网站在线观看免费 | 伊人影院综合 | 亚洲精品aaaa | 精品在线观看视频 | 亚洲成人国产精品 | 操在线视频 | 亚洲精品自拍视频 | 日韩av手机在线免费观看 | 91高跟黑色丝袜呻吟在线观看 | 日本欧美一区二区三区不卡视频 | 国产一二区| 四虎看片 | 国产精品一页 | 97潮色| 免费看日产一区二区三区 | 免费精品一区二区 | 中文字幕www | 正在播放国产一区 | 久久福利片| 黄色日韩 | 亚洲欧美一区二区三区四区 | 午夜精品久久久久久久99黑人 | 国产精品久久久久久久午夜 | 亚洲综合图区 | 亚洲成人免费网站 | 免费成人福利视频 | 毛片最新网址 | 色网站女女 | 操人视频在线观看 | 99热免费在线观看 | 国产女主播喷水高潮网红在线 |