note 125738 added to function.similar-text

From: Date: Fri, 29 Jan 2021 15:37:05 +0000
Subject: note 125738 added to function.similar-text
Groups: php.notes 
Request: Send a blank email to php-notes+get-219275@lists.php.net to get a copy of this message
To calculate the percentage of similarity between two strings without depending on the order of the parameters and be case insensitive, I use this function based on levenshtein's distance: <?php // string similarity calculated using levenshtein static function similarity($a, $b) { return 1 - (levenshtein(strtoupper($a), strtoupper($b)) / max(strlen($a), strlen($b))); } ?> This will always return a number between 0 and 1, representing the percentage, for instance 0.8 represents 80% similar strings. If you want this to be case-sensitive, just remove the strtoupper() functions. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.166 (proxied: 167.61.57.206) ---- Manual Page -- http://php.net/manual/en/function.similar-text.php Edit -- https://master.php.net/note/edit/125738 Del: integrated -- https://master.php.net/note/delete/125738/integrated Del: useless -- https://master.php.net/note/delete/125738/useless Del: bad code -- https://master.php.net/note/delete/125738/bad+code Del: spam -- https://master.php.net/note/delete/125738/spam Del: non-english -- https://master.php.net/note/delete/125738/non-english Del: in docs -- https://master.php.net/note/delete/125738/in+docs Del: other reasons-- https://master.php.net/note/delete/125738 Reject -- https://master.php.net/note/reject/125738 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#219275) next »