Voting

: min(nine, one)?
(Example: nine)

The Note You're Voting On

vojtech dot hordejcuk at gmail dot com
15 years ago
Based on one lad's code, I created following function for creating something like HTML diff. I hope it will be useful.

<?php
private function diff ($old, $new)
{
$old = preg_replace ('/ +/', ' ', $old);
$new = preg_replace ('/ +/', ' ', $new);

$lo = explode ("\n", trim ($old) . "\n");
$ln = explode ("\n", trim ($new) . "\n");
$size = max (count ($lo), count ($ln));

$equ = array_intersect ($lo, $ln);
$ins = array_diff ($ln, $lo);
$del = array_diff ($lo, $ln);

$out = '';

for (
$i = 0; $i < $size; $i++)
{
if (isset (
$del [$i]))
{
$out .= '<p><del>' . $del [$i] . '</del></p>';
}

if (isset (
$equ [$i]))
{
$out .= '<p>' . $equ [$i] . '</p>';
}

if (isset (
$ins [$i]))
{
$out .= '<p><ins>' . $ins [$i] . '</ins></p>';
}
}

return
$out;
}
?>

<< Back to user notes page

To Top