This page demonstrate the FineDiff
class (as in “fine granularity diff”) I wrote – starting from scratch – to generate a lossless (won't eat your line breaks), compact opcodes string listing the sequence of atomic actions (copy/delete/insert) necessary to transform one string into another (thereafter referred as the “From” and “To” string). The “To” string can be rebuilt by running the opcodes string on the “From” string. The FineDiff
class allows to specify the granularity, and up to character-level granularity is possible, in order to generate the smallest diff possible (at the potential cost of increased CPU cycles.)
Typical usage:
include 'finediff.php';
$opcodes = FineDiff::getDiffOpcodes($from_text, $to_text /* , default granularity is set to character */);
// store opcodes for later use...
Later, $to_text
can be re-created from $from_text
using $opcodes
as follow:
include 'finediff.php';
$to_text = FineDiff::renderToTextFromOpcodes($from_text, $opcodes);
Try it by inserting your own text, or Use sample text, or Start from scratch, or just use the plain Online diff viewer: