note 94410 added to function.array-diff
| From: | vojtech dot hordejcuk at gmail dot com | Date: | Tue, 03 Nov 2009 15:15:51 +0000 |
| Subject: | note 94410 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162356@lists.php.net to get a copy of this message | ||
Based on one lad's code, I created following function for creating something like HTML diff. I
hope it will be useful.
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;
}
----
Server IP: 89.185.144.38
Probable Submitter: 157.190.100.224
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/94410
Del: integrated -- https://master.php.net/note/delete/94410/integrated
Del: useless -- https://master.php.net/note/delete/94410/useless
Del: bad code -- https://master.php.net/note/delete/94410/bad+code
Del: spam -- https://master.php.net/note/delete/94410/spam
Del: non-english -- https://master.php.net/note/delete/94410/non-english
Del: in docs -- https://master.php.net/note/delete/94410/in+docs
Del: other reasons-- https://master.php.net/note/delete/94410
Reject -- https://master.php.net/note/reject/94410
Search -- https://master.php.net/manage/user-notes.php