Compare files with PHP

0

Is there any tool or way to create a file comparison with PHP? I would like something like Beyond Compare but within the Browser.

We have a change control system in applications that we develop here, and this system is web, there we wanted to create something that could control who was and what source files were replaced by programmers, but how they are accustomed to Beyond Compare we would like to do something similar.

    
asked by anonymous 12.09.2014 / 15:47

2 answers

3

I found this class here [mirror] that implements a Diff in PHP. I tried with a .json simple file, making a copy and deleting an object, the result is:

And this is PHP test file:

<html><head>
    <style>
    .diff td{
      vertical-align : top;
      white-space    : pre;
      white-space    : pre-wrap;
      font-family    : monospace;
    }
    .diffUnmodified { background-color: #BAF4FA; }
    .diffDeleted { background-color: #EEB4B4; }
    .diffInserted { background-color: #A9F2A4; }
    </style>
</head>
<body>
    // output the result of comparing two files as a table
    <?php 
    require_once './class.Diff.php';
    echo Diff::toTable( Diff::compareFiles('calendar-1.json', 'calendar-2.json') ); 
    ?>
</body></html>
    
12.09.2014 / 18:29
1

It has a form in example # 1 in the PHP manual xdiff_file_diff() that does unified diff of two PHP files with context length of 2.

<?php
$old_version = 'my_script.php';
$new_version = 'my_new_script.php';

xdiff_file_diff($old_version, $new_version, 'my_script.diff', 2);
?>

Remembering that it is not for binary files.

    
12.09.2014 / 17:44