PHP code example of mistralys / text-diff

1. Go to this page and download the library: Download mistralys/text-diff library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mistralys / text-diff example snippets


use Mistralys\Diff\Diff;

$diff = Diff::compareStrings('String 1', 'String 2');

use Mistralys\Diff\Diff;

$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');

use Mistralys\Diff\Diff;

$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');

$string = $diff->toString();
$html = $diff->toHTML();
$table = $diff->toHTMLTable();
$array = $diff->toArray();

use Mistralys\Diff\Diff;

$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');

$diff->setCompareCharacters(true);

use Mistralys\Diff\Diff;

$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');
$styler = Diff::createStyler();

use Mistralys\Diff\Diff;

$styler = Diff::createStyler();

$css = $styler->getCSS(); // get the raw CSS styles
$tag = $styler->getStyleTag(); // CSS styles with a <style> tag
$path = $styler->getStylesheetPath(); // absolute path to the file
$url = $styler->getStylesheetURL('/vendor'); // URL to the file, given the vendor folder URL

use Mistralys\Diff\Diff;

$diff = Diff::compareStrings('String 1', 'String 2');

echo Diff::createStyler()->getStyleTag();
echo $diff->toHTML();