PX : code

diff function by Joris van Eil
Download this code


<?php
function diff($s1$s2$s 0$e 0$sourcedep = array(), $destdep = array(), $sub 0)
{
  if(
$sub==0$e strlen($s1)-1;
    if(
strpos($s2,substr($s1,$s,($e-$s+1)))!==false)                               
    {
      
$b $s;
        
$c $e;
    for(
$x $s 1;$x>=0;$x--) 
      {
          if(
strpos($s2,substr($s1,$x,($e-$x+1)))!==false$b $x
            else break;
    }
    for(
$x $e 1;$x<(strlen($s1)-1);$x++) 
      {
          if(
strpos($s2,substr($s1,$b,($x-$b+1)))!==false$c $x
            else break;
    }
        for(
$x=$b;$x<=$c;$x++)                       
        {
          if(
$destdep[($x $b) + strpos($s2,substr($s1,$b,($c-$b+1)))]["l"]<($c $b 1) && $sourcedep[$x]["l"]<($c $b 1))   
            {                                                       
            if(
is_array($destdep[($x $b) + strpos($s2,substr($s1,$b,($c-$b+1)))])) $sourcedep[$destdep[($x $b) + strpos($s2,substr($s1,$b,($c-$b+1)))]["a"]] = null
                
$sourcedep[$x]["a"] = ($x $b) + strpos($s2,substr($s1,$b,($c-$b+1))); 
        
$sourcedep[$x]["l"] = $c $b 1;     
              
$destdep[($x $b) + strpos($s2,substr($s1,$b,($c-$b+1)))]["a"] = $x
        
$destdep[($x $b) + strpos($s2,substr($s1,$b,($c-$b+1)))]["l"] = $c $b 1
          }
        }
    }
    if(
strpos($s2,substr($s1,$s,($e-$s+1)))===false&&strlen(substr($s1,$s,($e-$s+1)))>=2
    {
        
diff($s1$s2$s$s round(($e-$s+1)/2) - 1, &$sourcedep, &$destdep1); 
        
diff($s1$s2$s round(($e-$s+1)/2), $e, &$sourcedep, &$destdep1); 
    }
    if(
$sub == 0
    {
    
ksort($sourcedep);
        
ksort($destdep);
      foreach(
$sourcedep as $key => $val) if(!is_array($sourcedep[$key])) unset($sourcedep[$key]);
      foreach(
$destdep as $key => $val) if(!is_array($destdep[$key])) unset($destdep[$key]);
    
$result ["s"] = $sourcedep;
        
$result ["d"] = $destdep;
        return 
$result;
    }
}
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.