The xdiff class is a replacement of system diff command, but only written in PHP, and without dependancy.
It allow to generate Normal, Unified or SideBySide differences between two files or two strings.
$xdiff = new Domframework\Xdiff ();
$res = $xdiff->diff ("\n", "NEWLINE\n");
1c1
<
---
> NEWLINE
$xdiff = new Domframework\Xdiff ("unified");
$res = $xdiff->diff ("\n", "NEWLINE\n");
--- Original 2019-03-15 14:12:25.000000000 +0100
+++ New 2019-03-15 14:12:25.000000000 +0100
@@ -1 +1 @@
-
+NEWLINE
$xdiff = new Domframework\Xdiff ("sideBySide");
$res = $xdiff->diffFile ("/tmp/test_xdiff1", "/tmp/test_xdiff2");
Result :
> This is an important
> notice! It should
> therefore be located at
> the beginning of this
> document!
>
This part of the This part of the
document has stayed the document has stayed the
same from version to same from version to
version. It shouldn't version. It shouldn't
be shown if it doesn't be shown if it doesn't
change. Otherwise, that change. Otherwise, that
would not be helping to would not be helping to
compress the size of the compress the size of the
changes. changes.
This paragraph contains <
text that is outdated. <
It will be deleted in the <
near future. <
<
It is important to spell It is important to spell
check this dokument. On | check this document. On
the other hand, a the other hand, a
misspelled word isn't misspelled word isn't
the end of the world. the end of the world.
Nothing in the rest of Nothing in the rest of
this paragraph needs to this paragraph needs to
be changed. Things can be changed. Things can
be added after it. be added after it.
>
> This paragraph contains
> important new additions
> to this document.
Namespace Domframework
/** Create a diff from two strings, array or files The output is compatible with "patch" command.
No property available
/**
The constructor allow to choose the output.
@param string $output
The output mode [Normal|Unified|SideBySide]
/** Compute the differences between two arrays $array1 and $array2@param array $array1
The first array to compare@param array $array2
The second array to compare@return
array The data in internal format
/** Compute the differences between two strings $string1 and $string2@param string $string1
The first string to compare@param string $string2
The second string to compare
/** Compute the differences between two arrays $array1 and $array2@param array $array1
The first array to compare@param array $array2
The second array to compare
/** Compute the differences between two files $file1 and $file2@param string $file1
The first file to use to compare@param string $file2
The second file to use to compare
/**
Allow to set the side by side width to the maximum allowed by screenWidth
@param integer $screenWidth
The maximum width of the screen