# Posted By

voodoochilo on 10/16/10

# Statistics

Viewed 543 times
Favorited by 0 user(s)

# Dice Coefficient in PHP

/ Published in: PHP
`<?php /*---------------------------------------------------------------------------- 	PhpDiceCoeff - An Implementation of the Dice-Coefficient in PHP 	Version 0.0.01a	(C)2010 by Emil Endgut  	==============================================================	This is Friendware, which means that you may use it as if you	wrote it, after	you became a friend of mine on Facebook.	Please Visit:	http://www.facebook.com/profile.php?id=100001062124472	============================================================== 	Usage: 		php dice.php "stringA" "stringB" ----------------------------------------------------------------------------*/ \$str_a =\$argv[1];\$str_b =\$argv[2]; echo "dice(\"".\$str_a . "\", \"". \$str_b. "\") = " . dice(\$str_a, \$str_b) . "\n"; function dice(\$a, \$b){	\$az=zerleg(\$a);	\$ac=count(\$az); 	\$bz=zerleg(\$b);	\$bc=count(\$bz); 	\$is=array_intersect(\$az, \$bz);	\$ic=count(\$is); 	return 2 * \$ic / (\$ac + \$bc);} function zerleg(\$str){	\$a=strtolower(\$str);	\$len=strlen(\$a); 	for(\$n=2;\$n<\$len;\$n++)		for(\$i=0 ; \$i+\$n<=\$len ; \$i++)			\$arr[]=substr(\$a,\$i,\$n);	return \$arr;}   ?>`