Getting started
Compare two strings, then choose a renderer for the destination of the result.
<?php
require __DIR__.'/vendor/autoload.php';
use Alto\Code\Diff\Diff;
use Alto\Code\Diff\Renderer\UnifiedRenderer;
$old = "line one\nline two\n";
$new = "line one\nline two changed\n";
$result = Diff::build()->compare($old, $new);
echo (new UnifiedRenderer('old.txt', 'new.txt'))->render($result);The output is a standard unified diff:
--- old.txt
+++ new.txt
@@ -1,2 +1,2 @@
line one
-line two
+line two changedDiff::build() creates an immutable builder. Each configuration method returns a new instance, so a configured builder can be reused safely.
Next, configure the comparison, select another renderer, or work with patches.