J'ai le code PHP 4 pour vérifier les différences de deux fichiers, cela fonctionne très bien sur les anciens serveurs avec les versions PHP 4, mais sur les nouveaux serveurs, je reçois des erreurs. Par exemple:Le code PHP 4 donne des erreurs sur php 5
$maxlen
est pas défini
Et le plan fonctionnel ne fonctionne pas sur le nouveau serveur. Quelqu'un sait comment changer cela pour une version récente de PHP?
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);
}
J'ai essayé le manuel? 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
D'où obtenez-vous '$ maxlen'? – codingbiz