diff options
-rw-r--r-- | h-source/Application/Include/myFunctions.php | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index d0d51bf..9e05ed2 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -128,16 +128,33 @@ function getOrderByClause($string) return $orderBy; } +//remove empty elements +function removeEmptyStrings($oArray) +{ + $nArray = array(); + foreach ($oArray as $oValue) + { + if (strcmp($oValue,'') !== 0) + { + $nArray[] = $oValue; + } + } + return $nArray; +} -function diff($old, $new){ +function diff($old, $new) +{ $maxlen = 0; - foreach($old as $oindex => $ovalue){ -// $nkeys = getNewKeys($new,$ovalue); + foreach($old as $oindex => $ovalue) + { $nkeys = array_keys($new, $ovalue); - foreach($nkeys as $nindex){ +// echo memory_get_peak_usage(true)."<br />"; + foreach($nkeys as $nindex) + { $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1; - if($matrix[$oindex][$nindex] > $maxlen){ + if($matrix[$oindex][$nindex] > $maxlen) + { $maxlen = $matrix[$oindex][$nindex]; $omax = $oindex + 1 - $maxlen; $nmax = $nindex + 1 - $maxlen; @@ -151,13 +168,15 @@ function diff($old, $new){ diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); } -function htmlDiff($old, $new){ +function htmlDiff($old, $new) +{ $old = str_replace("\r\n"," \r\n ",$old); $new = str_replace("\r\n"," \r\n ",$new); $ret = null; - $diff = diff(explode(' ', $old), explode(' ', $new)); - foreach($diff as $k){ + $diff = diff(removeEmptyStrings(explode(' ', $old)),removeEmptyStrings(explode(' ', $new))); + foreach($diff as $k) + { if(is_array($k)) $ret .= (!empty($k['d'])?"<del>".implode(' ',$k['d'])."</del> ":''). (!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":''); @@ -167,7 +186,6 @@ function htmlDiff($old, $new){ } -//a cosa serve? function applyBreaks($values,$fields) { $fieldsArray = explode(',',$fields); |