PHP code example of gathercontent / htmldiff

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

    

gathercontent / htmldiff example snippets


$old = '<span>This is a string</span>';
$new = '<span>This is a text</span>';

$htmldiff = new Htmldiff;
$result = $htmldiff->diff($old, $new);

// result: <span>This is a <del>string</del><ins>text</ins></span>

$old = '<p>Hello world, how do you do</p>';
$new = '<p>Hello world, how do <strong>you</strong> do</p>';

$htmldiff = new Htmldiff;
$result = $htmldiff->diff($old, $new);

// result: <p>Hello world, how do <del>you</del><strong><ins>you</ins></strong> do</p>

$old = '<p>Hello world</p><p>How do you do</p>';
$new = '<p>Hello world</p><ul><li>first point</li><li>second point</li></ul><p>How do you do</p>';

$htmldiff = new Htmldiff;
$result = $htmldiff->diff($old, $new);

// result: <p>Hello world</p><ul><li><ins>first point</ins></li><li><ins>second point</ins></li></ul><p>How do you do</p>