PHP code example of wxb / funcompare

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

    

wxb / funcompare example snippets


use Wxb\Funcompare\Funcompare;

$old = 'A tool compare text differences is funny';
$new = 'A tool that compare text differences';

$fc = new Funcompare();
$res = $fc->compareText($old, $new);
echo $res;

// A tool <new:that> compare text differences <old:is> <old:funny>


use Wxb\Funcompare\Funcompare;

$old = [
    ["id" => 1, "name" => "xxx", "age" => 18, "cart" => [["id" => 100, "name" => "rice->你"]], "sex" => "男/0"],
    ["id" => 2, "name" => "aaa", "age" => 18],
];
$new = [
    ["id" => 1, "name" => "yyy", "age" => 20, "cart" => [["id" => 100, "name" => "banana/我"]], "sex" => 1, "address" => ["provice" => "陕西省", "city" => "宝鸡市"]],
    ["id" => 2, "name" => "bbb", "age" => 18],
];

$fc = new Funcompare();
$res = $fc->compareArray($old, $new);
var_export($res);

/*
array (
  0 => 
  array (
    'name' => 
    array (
      'old' => 'xxx',
      'new' => 'yyy',
    ),
    'age' => 
    array (
      'old' => 18,
      'new' => 20,
    ),
    'cart' => 
    array (
      0 => 
      array (
        'name' => 
        array (
          'old' => 'rice->你',
          'new' => 'banana/我',
        ),
      ),
    ),
    'sex' => 
    array (
      'old' => '男/0',
      'new' => 1,
    ),
    'address' => 
    array (
      'old' => NULL,
      'new' => 
      array (
        'provice' => '陕西省',
        'city' => '宝鸡市',
      ),
    ),
  ),
  1 => 
  array (
    'name' => 
    array (
      'old' => 'aaa',
      'new' => 'bbb',
    ),
  ),
)
*/

use Wxb\Funcompare\Funcompare;

$old = '[{"id":1,"name":"xxx","age":18,"cart":[{"id":100,"name":"rice->你"}], "sex":"男/0"},{"id":2,"name":"aaa","age":18}]';
$new = '[{"id":1,"name":"yyy","age":20,"cart":[{"id":100,"name":"banana/我"}], "sex":1, "address":{"provice":"陕西省","city":"宝鸡市"}},{"id":2,"name":"bbb","age":18}]';


$fc = new Funcompare();
$res = $fc->compareJson($old, $new);
echo $res

// [{"name":{"old":"xxx","new":"yyy"},"age":{"old":18,"new":20},"cart":[{"name":{"old":"rice->你","new":"banana/我"}}],"sex":{"old":"男/0","new":1},"address":{"old":null,"new":{"provice":"陕西省","city":"宝鸡市"}}},{"name":{"old":"aaa","new":"bbb"}}]


use Wxb\Funcompare\Funcompare;

$fromA = 'A tool compare text differences is funny';
$fromB = 'A tool that compare text differences';

$fc = new Funcompare();
$res = $fc->label('a', 'b')->compareText($fromA, $fromB);
echo $res;

// A tool <b:that> compare text differences <a:is> <a:funny>