4

In short I am looking for something like google-diff-match-patch in PHP.

I have had a look at some similar questions at SO, and also at the algorithm provided here, but all of them fail:

diff("draßen", "da draußen")

should not give

<del>draßen</del> <ins>da draußen</ins> 

(which is kind of stupid for my purpose, because I want to compare file names), but (try here)

<ins>da </ins>dra<ins>u</ins>ßen

Is there a code snippet in PHP that does this? Unfortunately, I cannot use (i.e. install) external packages.

4
  • Not sure this is what you want / need, but give this PHP function a look: php.net/manual/en/function.similar-text.php. There's also the levenshtein algorithm there, at "See also". Commented Jul 22, 2010 at 9:30
  • You could define a threshhold percentage for when the check 'in-word' diffs with similar_text(). Haven't got the time to work out an example a.t.m. though. Commented Jul 22, 2010 at 9:36
  • In the API Documentation on the Google Code page you link to there is mention of a partial PHP implementation - although this is not part of the repository as yet. Commented Jul 22, 2010 at 10:25
  • @Francisc: No, it's not -- but in fact I'm using right this function to select filenames similar to the one given. Now I want to highlight the differences... Commented Jul 22, 2010 at 16:04

4 Answers 4

4

https://github.com/gorhill/PHP-FineDiff supports character-wise diff and can render the differences in HTML

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

Comments

2

The PEAR Package Text_Diff provides Inline-Diffs.

2 Comments

I know. But I cannot install pear packages afaik.
You can download the Text_Diff Package as tgz. So you could extract the functions/algorithms you actually need.
2

There is a php version of google-diff-match-patch available here: https://github.com/nuxodin/diff_match_patch-php

Comments

2

There is a port of fresh version google-diff-match-patch library. It is much faster than previous and have no problems wth utf8.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.