note 37290 added to function.similar-text

From: Date: Sun, 09 Nov 2003 09:23:48 +0000
Subject: note 37290 added to function.similar-text
Groups: php.notes 
Request: Send a blank email to php-notes+get-60155@lists.php.net to get a copy of this message
A minor correction or two to georgesk's code of 9 March 2002: He initialises the array with: $LCS_Length_Table = array(array(128),array(128)); and then resets the relevant columns to 0, except that this doesn't create a 128-by-128 array, which I think is his intention. The code to do that is - and if anyone knows a prettier version, please post! - something like: $LCS_Length_Table = array_pad(array(), 128, array_pad(array(), 128, 0)); Alternatively, if you want to allocate only as much space as needed, but no more than 128 chars per string, then use: $LCS_Length_Table = array_pad(array(), min($m, 128)+1, array_pad(array(), min($n, 128)+1, 0)); (You need the +1 because we actually use indexes up to strlen($s1) and strlen($s2), but PHP arrays are 0-based of course). Other than that though, some very nice code! :-) Christo ---- Manual Page -- http://www.php.net/manual/en/function.similar-text.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37290 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37290&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37290&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60155) next »