PHP code example of joyme123 / textdiff

1. Go to this page and download the library: Download joyme123/textdiff 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/ */

    

joyme123 / textdiff example snippets



TextDiff\TextDiff;

$textDiff = new TextDiff();
$diffResult = $textDiff->diff('ABCD', 'AEBF');    // array result

var_dump($diffResult);

echo $textDiff->diff('湖山秋景远,千色变其中', '湖光秋色', true);   // html result

array(6) {
  [0] =>
  array(2) {
    [0] =>
    string(1) "A"       // 值
    [1] =>
    string(1) "u"       // u是unchange,代表这个值没有改变
  }
  [1] =>
  array(2) {
    [0] =>
    string(1) "E"       
    [1] =>
    string(1) "a"       // a是append,代表这个值时候新增的
  }
  [2] =>
  array(2) {
    [0] =>
    string(1) "B"
    [1] =>
    string(1) "u"
  }
  [3] =>
  array(2) {
    [0] =>
    string(1) "C"
    [1] =>
    string(1) "d"       // d是delete,代表这个值是删除的
  }
  [4] =>
  array(2) {
    [0] =>
    string(1) "D"
    [1] =>
    string(1) "d"
  }
  [5] =>
  array(2) {
    [0] =>
    string(1) "F"
    [1] =>
    string(1) "a"
  }
}