Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Character-wise string diff in PHP

Tags:

string

php

diff

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.

like image 588
fuenfundachtzig Avatar asked Dec 29 '22 09:12

fuenfundachtzig


2 Answers

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

like image 137
R. Hill Avatar answered Jan 10 '23 17:01

R. Hill


The PEAR Package Text_Diff provides Inline-Diffs.

like image 31
Benjamin Cremer Avatar answered Jan 10 '23 16:01

Benjamin Cremer