0

How can I check and find differences(e.g svn diff, netbeans diff) between two files using php?

Platform : Win 7 32bit, PHP 5.4.7 (VC9 X86 32bit thread safe), XAMPP Version 1.8.1

Loaded extensions : Core, bcmath, calendar, ctype, date, ereg, filter, ftp, hash, iconv, json, mcrypt, SPL, odbc, pcre, Reflection, session, standard, mysqlnd, tokenizer, zip, zlib, libxml, dom, PDO, bz2, SimpleXML, wddx, xml, xmlreader, xmlwriter, apache2handler, Phar, curl, mbstring, exif, gd, gettext, mysql, mysqli, pdo_mysql, pdo_sqlite, soap, sockets, sqlite3, xmlrpc, xsl, mhash

2
  • 1
    use, file() function, compare lines, highlight different parts. P.S.: Have you tried anything? Commented May 14, 2013 at 5:57
  • @CORRUPT I didn't find any script I used meld found from this answer stackoverflow.com/questions/11895570/… I could have created by my self but for now I need quick solution Commented May 14, 2013 at 6:11

2 Answers 2

2

This all depends on how you wish to compare the files. Are they text files or binary files etc. If we assume they are text files you have to decide if white spaces should be ignored etc. What you could do is open the two files to compare and go through them character by character and compare them. What it boils down to is to solve the Longest Common Sub-sequence problem. I would recommend you to start looking at algorithms for comparing like found here for example

http://en.wikipedia.org/wiki/Diff#Algorithm

Another approach would be to include patch (which can be found for Windows to) and run that in the background to find differences and build patch files (since my guess is that you want to find the differences and be able to store them and maybe apply them later?)

Sign up to request clarification or add additional context in comments.

Comments

2

XDiff extension is useful to your case,

xdiff extension enables you to create and apply patch files containing differences between different revisions of files.

This extension supports two modes of operation - on strings and on files, as well as two different patch formats - unified and binary. Unified patches are excellent for text files as they are human-readable and easy to review. For binary files like archives or images, binary patches will be adequate choice as they are binary safe and handle non-printable characters well.

Reference:

http://php.net/manual/en/function.xdiff-file-diff.php

4 Comments

Thanks for the reply. I don't have xdiff installed.
download and install the dll files into ext folder inside xampp folder php.net/manual/en/install.windows.building.php
This link is dead php.net/manual/en/install.windows.building.php and I can't build for windows now because it will take some time

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.