note 22347 deleted from function.strcmp by philip

From: Date: Thu, 28 Nov 2002 04:04:11 +0000
Subject: note 22347 deleted from function.strcmp by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-40063@lists.php.net to get a copy of this message
Here is a (maybe not very good coded) function that returns the amount of chars which are not equal. for example xstrcmp("abcd","dcba") returns 0 i am not 100%ly sure that this function works function xstrcmp($string1, $string2) { $diff=0; for($i=0;$i<longest($string1,$string2);$i++) { $ok=0; if(($chr1=substr($string1,$i,1))==FALSE) { $diff++; continue; } if($i>=strlen($string2)) { $diff++; continue; } for($j=0;$j<longest($string1,$string2);$j++) if($chr1==substr($string2,$j,1)) { $string2=cutout($string2,$j); $string1=cutout($string1,$i); $ok=1; break; } if(!$ok) $diff++; } return $diff; } function longest($string1,$string2) { if(strlen($string1)>strlen($string2)) return strlen($string1); return strlen($string2); } function cutout($string,$index) { return substr($string,0,$index).substr($string,$index+1); }

« previous php.notes (#40063) next »