note 56724 added to function.soundex

From: Date: Tue, 13 Sep 2005 15:25:38 +0000
Subject: note 56724 added to function.soundex
Groups: php.notes 
Request: Send a blank email to php-notes+get-95121@lists.php.net to get a copy of this message
Rewritten, maybe -- but the algorithm has some obvious optimisations which can be done, for example... function text__soundex( $text ) { $k = ' 123 12 22455 12623 1 2 2'; $nl = strlen( $tN = strtoupper( $text ) ); $p = trim( $k{ ord( $tS = $tN{0} ) - 65 } ); for( $n = 1; $n < $nl; ++$n ) if( ( $l = trim( $k{ ord( $tN{ $n } ) - 65 } ) ) != $p ) $tS .= ( $p = $l ); return substr( $tS . '000', 0, 4 ); } // Notes: // $k is the $key, essentially $SoundKey inverted // $tN is the uppercase of the text to be optimised // $tS is the partaully generated output // $l is the current letter, $p the previous // $n and $nl are iteration indicies // 65 is ord('A'), precalculated for speed // none ascii letters are not supported // watch the brackets, quite a mixture here (Code has suffered only basic tests, though it appears to match the output of PHP's soundex(), speed untested -- though this should be /much/ faster than a4_perfect's rewrite due to the removal of most loops and compares.) C 2005-09-13 ---- Manual Page -- http://www.php.net/manual/en/function.soundex.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56724 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56724&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56724&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56724&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56724&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56724&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56724&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56724&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95121) next »