두 파일의 차이를 확인하는 PHP 4 코드가 있습니다. PHP 4 버전을 사용하는 이전 서버에서는 정상적으로 작동하지만 새 서버에서는 오류가 발생합니다. 예를 들어 :PHP 4 코드는 PHP 5에서 오류가 발생합니다.
정의 그리고 기능적으로는 새 서버에서 작동하지 않습니다. 누구든지 최근 PHP 버전에서이를 어떻게 변경해야하는지 알고 있습니까?
$maxlen
에는이
function diff($old, $new){
foreach($old as $oindex => $ovalue){
$nkeys = array_keys($new, $ovalue);
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){
$maxlen = $matrix[$oindex][$nindex];
$omax = $oindex + 1 - $maxlen;
$nmax = $nindex + 1 - $maxlen;
}
}
}
if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
return array_merge(
diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
array_slice($new, $nmax, $maxlen),
diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}
function htmlDiff($old, $new){
$preg="/[\s,]+/";
$old=str_replace(">","> ",$old);
$new=str_replace(">","> ",$new);
$old=str_replace("<"," <",$old);
$new=str_replace("<"," <",$new);
$diff = diff(preg_split($preg, $old),preg_split($preg, $new));
foreach($diff as $k){
if(is_array($k))
$ret .= (!empty($k['d'])?"<div style='BACKGROUND-COLOR: red'>".implode(' ',$k['d'])."</div> ":'').
(!empty($k['i'])?"<div style='BACKGROUND-COLOR: yellow'>".implode(' ',$k['i'])."</div> ":'');
else $ret .= $k . ' ';
}
return $ret;
}
function creatediff($oldurl,$newurl,$diffurl){
$sold= file_get_contents($oldurl);
$snew= file_get_contents($newurl);
$diff=htmlDiff($sold,$snew);
$diff=preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\s|\+)[^"]*"))#','$1="'.$newurl.'/$2"',$diff);
file_put_contents($diffurl,$diff);
}
설명서를 시도 했습니까? http://php.net/manual/en/faq.migration5.php – Repox
http://stackoverflow.com/questions/2487021/what-is-the-difference-betwen-variable-in-php4-and-php5 – apoq
어디에서'$ maxlen'을 얻고 있습니까? – codingbiz