atrsimilar_diff

Versions
6.1
atrsimilar_diff($old, $new)

Compute the differences between two strings.

▾ 2 functions call atrsimilar_diff()

atrsimilar_result in atr/modules/atrsimilar/includes/atrsimilar.result.inc
Display an overview of similar strings.
atrsimilar_similarity in atr/modules/atrsimilar/includes/atrsimilar.review.inc
Find two strings their similarity.

Code

atr/modules/atrsimilar/includes/atrsimilar.review.inc, line 113

<?php
function atrsimilar_diff($old, $new) {
  $tokens = atrsimilar_tokenize($old, $new);
  $prefix = atrsimilar_prefix($tokens);
  $suffix = atrsimilar_suffix($tokens);
  $length[0] = count($tokens[0]);
  $length[1] = count($tokens[1]);
  $matrix = atrsimilar_lcs_matrix($tokens, $length);
  atrsimilar_diff_build($tokens, $matrix, $length);

  // Add the previously trimmed prefix and suffix.
  foreach (array(0, 1) as $i) {
    if ($prefix) {
      array_unshift($tokens[$i], atrsimilar_expand_token($prefix, TRUE));
    }
    if ($suffix) {
      array_push($tokens[$i], atrsimilar_expand_token($suffix, TRUE));
    }
  }

  return array(atrsimilar_diff_merge($tokens[0]), atrsimilar_diff_merge($tokens[1]));
}
?>