By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

HTML Diff problem

P: n/a
Hi,

I am working on an HTML WYSISYG Wiki and need to display a diff page like
WikiPedia does if two people edit a file at the same time to give the second
user the diff. Basically with additions in red and deletions in red strike
though.

There seem to be several in Perl and Python and many diff programs which all
seem to be line based and work on text written in PHP.

So I am after either existing PHP code to do an HTML diff or some help
forming an algorithm todo this.

Many thanks in advance,

Aaron
Oct 22 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On 22 Oct, 18:54, "Aaron Gray" <ang.use...@gmail.comwrote:
Hi,

I am working on an HTML WYSISYG Wiki and need to display a diff page like
WikiPedia does if two people edit a file at the same time to give the second
user the diff. Basically with additions in red and deletions in red strike
though.

There seem to be several in Perl and Python and many diff programs which all
seem to be line based and work on text written in PHP.

So I am after either existing PHP code to do an HTML diff or some help
forming an algorithm todo this.

Many thanks in advance,
Obvious solution would be to use 'diff' from popen / exec etc

Another approach would be to hack the code from an existing
implementation (like DokuWiki).

But the very first hit for 'php diff' in Google provides what you
describe.

C.
Oct 23 '08 #2

P: n/a
"C. (http://symcbean.blogspot.com/)" <co************@gmail.comwrote in
message
news:60**********************************@d70g2000 hsc.googlegroups.com...
On 22 Oct, 18:54, "Aaron Gray" <ang.use...@gmail.comwrote:
>Hi,

I am working on an HTML WYSISYG Wiki and need to display a diff page like
WikiPedia does if two people edit a file at the same time to give the
second
user the diff. Basically with additions in red and deletions in red
strike
though.

There seem to be several in Perl and Python and many diff programs which
all
seem to be line based and work on text written in PHP.

So I am after either existing PHP code to do an HTML diff or some help
forming an algorithm todo this.

Many thanks in advance,

Obvious solution would be to use 'diff' from popen / exec etc
This is not HTML based.
Another approach would be to hack the code from an existing
implementation (like DokuWiki).
This is not HTML based.
But the very first hit for 'php diff' in Google provides what you
describe.
This is a straight diff not an HTML diff. The problem is comparing two HTML
files, not wiki text files.

Thanks anyway,

Aaron
Oct 23 '08 #3

P: n/a
On Oct 23, 6:39*pm, "Aaron Gray" <ang.use...@gmail.comwrote:
"C. (http://symcbean.blogspot.com/)" <colin.mckin...@gmail.comwrote in
messagenews:60**********************************@d 70g2000hsc.googlegroups..com...
On 22 Oct, 18:54, "Aaron Gray" <ang.use...@gmail.comwrote:
Hi,
I am working on an HTML WYSISYG Wiki and need to display a diff page like
WikiPedia does if two people edit a file at the same time to give the
second
user the diff. Basically with additions in red and deletions in red
strike
though.
There seem to be several in Perl and Python and many diff programs which
all
seem to be line based and work on text written in PHP.
So I am after either existing PHP code to do an HTML diff or some help
forming an algorithm todo this.
Many thanks in advance,
Obvious solution would be to use 'diff' from popen / exec etc

This is not HTML based.
Another approach would be to hack the code from an existing
implementation (like DokuWiki).

This is not HTML based.
But the very first hit for 'php diff' in Google provides what you
describe.

This is a straight diff not an HTML diff. The problem is comparing two HTML
files, not wiki text files.

Thanks anyway,

Aaron
There is no such thing as a HTML diff, or a wiki diff, or a
thingywosit diff. They all use the same algorithm. They scan a
string and look for differences on a line by line basis. You can feed
HTML data into them just as easily as any other kind of data.

For example, using http://www.holomind.de/phpnet/diff2.src.php:

Input 1:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="/js/jquery/jquery.js" />
</head>
<body>
<pLorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
sed purus ac
elit tempor lacinia. Fusce viverra! Duis elementum nisl nec metus.
Sed quis arcu.
Morbi tortor! Maecenas ac nisl sit amet felis euismod elementum. Sed
non lacus
sed mi vehicula congue. Vestibulum non felis egestas leo ultricies
ultricies.
Donec ornare scelerisque leo! Vivamus sed nunc quis augue
consectetuer eleifend.
Praesent cursus. Phasellus cursus, nunc eu placerat dictum, metus
leo volutpat
arcu, ac convallis tellus nunc in elit. Maecenas dignissim tincidunt
pede. Vivamus
eget metus. Integer luctus est interdum nibh. Curabitur condimentum
faucibus enim.
Nunc tincidunt ipsum et odio. </p>
<pDonec sed nunc. Fusce accumsan, felis dignissim faucibus cursus,
diam neque
pharetra libero, at rhoncus enim ipsum nec nulla. Donec sed metus.
Suspendisse
potenti. Nam suscipit vehicula risus. Integer vel arcu. Ut nec enim
pulvinar magna
tristique laoreet. Quisque viverra tellus a sapien. Praesent
fringilla. Duis mi
risus, tempus ut, venenatis quis, malesuada eget; velit. Cras nisi.
Nam et ligula.
Duis feugiat lorem at urna. </p>
<pSuspendisse potenti. Integer interdum, dolor sed ullamcorper
dictum; est augue
aliquet eros, at molestie augue est et nunc. Pellentesque habitant
morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Aenean ac
metus? Duis
vel nibh vitae odio hendrerit vulputate. Ut tortor. Ut fermentum
pellentesque
nulla. Sed eros dui, volutpat nec, ultrices feugiat, semper sit
amet, nunc. Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas.
Morbi hendrerit nibh. Pellentesque lacinia urna. Sed nisi ligula,
interdum quis,
volutpat ac, placerat commodo, metus. Curabitur venenatis venenatis
quam. Vivamus
cursus, dolor vitae rutrum tempus, erat ipsum volutpat pede, sed
cursus nunc mauris
in ligula. In eget justo id justo pulvinar malesuada. Etiam nisi
est, auctor vitae,
blandit vel, aliquet quis, metus. Cras dui magna, commodo posuere,
dictum convallis,
laoreet vitae, lorem. Praesent luctus, ante at dictum vestibulum, mi
urna pulvinar
velit, ut ultricies erat purus luctus sapien. Praesent molestie
turpis. Pellentesque
bibendum rutrum est. </p>
<pMauris adipiscing ante id neque. Nulla sit amet massa. Nam
consectetuer lorem
sed augue. Nullam in dui! Integer rutrum venenatis nisl.
Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Suspendisse
id sem eget est rhoncus lobortis. Cras consequat ligula a mi. In hac
habitasse
platea dictumst. Cras vel sem. Quisque adipiscing. Suspendisse
convallis justo
ac nulla. Vivamus tincidunt. In rutrum consequat lorem. </p>
</body>
</html>

Input 2:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lorem ipsum</title>
</head>
<body>
<pLorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
sed purus ac
elit tempor lacinia. Fusce viverra! Duis elementum nisl nec metus.
Sed quis arcu.
Morbi tortor! Maecenas ac nisl sit amet felis euismod elementum. Sed
non lacus
sed mi vehicula congue. Vestibulum non felis egestas leo ultricies
ultricies.
Donec ornare scelerisque leo. Vivamus sed nunc quis augue
consectetuer eleifend.
Praesent cursus. Phasellus cursus, nunc eu placerat dictum, metus
leo volutpat
arcu, ac convallis tellus nunc in elit. Maecenas dignissim tincidunt
pede. Vivamus
eget metus. Integer luctus est interdum nibh. Curabitur condimentum
faucibus enim.
Nunc tincidunt ipsum et odio. </p>
<pSuspendisse potenti. Integer interdum, dolor sed ullamcorper
dictum; est augue
aliquet eros, at molestie augue est et nunc. Pellentesque habitant
morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Aenean ac
metus? Duis
vel nibh vitae odio hendrerit vulputate. Ut tortor. Ut fermentum
pellentesque
nulla. Sed eros dui, volutpat nec, ultrices feugiat, semper sit
amet, nunc. Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas.
Morbi hendrerit nibh. Pellentesque lacinia urna. Sed nisi ligula,
interdum quis,
volutpat ac, placerat commodo, metus. Curabitur venenatis venenatis
quam. Vivamus
cursus, dolor vitae rutrum tempus, erat ipsum volutpat pede, sed
cursus nunc mauris
in ligula. In eget justo id justo pulvinar malesuada. Etiam nisi
est, auctor vitae,
blandit vel, aliquet quis, metus. Cras dui magna, commodo posuere,
dictum convallis,
laoreet vitae, lorem. Praesent luctus, ante at dictum vestibulum, mi
urna pulvinar
velit, ut ultricies erat purus luctus sapien. Praesent molestie
turpis. Pellentesque
bibendum rutrum est. </p>
<pLorem ipsum dolor sit amet, consectetuer adipiscing elit.
Vestibulum pede ipsum,
accumsan quis, porttitor ut, blandit sed, neque. Phasellus feugiat
commodo erat.
Praesent pulvinar augue sollicitudin nibh. Nunc tellus. Etiam ac
nunc. Praesent
eget lacus eu dolor fringilla vehicula. Nunc ac nulla nec dui
imperdiet cursus?
Sed dictum nunc nec erat. Donec laoreet magna nec est. Ut vel magna
vel est scelerisque
varius! In nulla leo, luctus sed, rhoncus vel, semper in, eros?
Vestibulum quam
dui, ultrices vitae, consectetuer in, aliquam nec, mauris. Morbi
congue pulvinar
quam! Vivamus tortor. Ut a leo et tortor accumsan pretium. Vivamus
mi. Curabitur
nulla lacus, commodo ut, iaculis vel, mollis eget, felis!
Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Vestibulum
ut diam. Maecenas facilisis semper mi. </p>
<pMauris adipiscing ante id neque. Nulla sit amet massa. Nam
consectetuer lorem
sed augue. Nullam in dui! Integer rutrum venenatis nisl.
Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Suspendisse
id sem eget est rhoncus lobortis. Cras consequat ligula a mi. In hac
habitasse
platea dictumst. Cras vel sem. Quisque adipiscing. Suspendisse
convallis justo
ac nulla. Vivamus tincidunt. In rutrum consequat lorem. </p>
<pUt blandit rhoncus tellus. Integer condimentum, turpis sit amet
tempor viverra;
tellus neque mollis dui, sit amet lacinia neque felis a enim. Nulla
ac velit sit
amet erat elementum dignissim. Cras suscipit, felis nec aliquet
auctor, augue
nisi ultrices purus, non convallis tortor odio ac nisi. Nam non
mauris eget nunc
congue euismod. Nam eget sapien at magna tempor aliquam. Nullam
bibendum tempor
velit. Phasellus in elit at mi vestibulum convallis. Integer sit
amet nulla. Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas.
Mauris nec magna id nibh sagittis posuere. Nulla a metus vitae
tortor tempus lobortis.
Praesent augue dolor, pulvinar vitae, accumsan vel, bibendum
faucibus, eros? Sed
a ipsum id dui varius blandit! In aliquet suscipit pede. </p>
</body>
</html>

Result:

1c1
< <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5,6c5
< <title>Untitled Document</title>
< <script type="text/javascript" src="/js/jquery/jquery.js" />
---
<title>Lorem ipsum</title>
13c12
< Donec ornare scelerisque leo! Vivamus sed nunc quis augue
consectetuer eleifend.
---
Donec ornare scelerisque leo. Vivamus sed nunc quis augue consectetuer eleifend.
18,23d16
< <pDonec sed nunc. Fusce accumsan, felis dignissim faucibus cursus,
diam neque
< pharetra libero, at rhoncus enim ipsum nec nulla. Donec sed metus.
Suspendisse
< potenti. Nam suscipit vehicula risus. Integer vel arcu. Ut nec
enim pulvinar magna
< tristique laoreet. Quisque viverra tellus a sapien. Praesent
fringilla. Duis mi
< risus, tempus ut, venenatis quis, malesuada eget; velit. Cras
nisi. Nam et ligula.
< Duis feugiat lorem at urna. </p>
37a31,41
<pLorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum pede ipsum,
accumsan quis, porttitor ut, blandit sed, neque. Phasellus feugiat commodo erat.
Praesent pulvinar augue sollicitudin nibh. Nunc tellus. Etiam ac nunc. Praesent
eget lacus eu dolor fringilla vehicula. Nunc ac nulla nec dui imperdietcursus?
Sed dictum nunc nec erat. Donec laoreet magna nec est. Ut vel magna velest scelerisque
varius! In nulla leo, luctus sed, rhoncus vel, semper in, eros? Vestibulum quam
dui, ultrices vitae, consectetuer in, aliquam nec, mauris. Morbi conguepulvinar
quam! Vivamus tortor. Ut a leo et tortor accumsan pretium. Vivamus mi. Curabitur
nulla lacus, commodo ut, iaculis vel, mollis eget, felis! Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis egestas.Vestibulum
ut diam. Maecenas facilisis semper mi. </p>
43a48,57
<pUt blandit rhoncus tellus. Integer condimentum, turpis sit amet tempor viverra;
tellus neque mollis dui, sit amet lacinia neque felis a enim. Nulla ac velit sit
amet erat elementum dignissim. Cras suscipit, felis nec aliquet auctor,augue
nisi ultrices purus, non convallis tortor odio ac nisi. Nam non mauris eget nunc
congue euismod. Nam eget sapien at magna tempor aliquam. Nullam bibendum tempor
velit. Phasellus in elit at mi vestibulum convallis. Integer sit amet nulla. Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac turpisegestas.
Mauris nec magna id nibh sagittis posuere. Nulla a metus vitae tortor tempus lobortis.
Praesent augue dolor, pulvinar vitae, accumsan vel, bibendum faucibus, eros? Sed
a ipsum id dui varius blandit! In aliquet suscipit pede. </p>
Oct 24 '08 #4

P: n/a
"Gordon" <go**********@ntlworld.comwrote in message
news:c4**********************************@k30g2000 hse.googlegroups.com...
>There is no such thing as a HTML diff, or a wiki diff, or a
thingywosit diff. They all use the same algorithm. They scan a
string and look for differences on a line by line basis. You can feed
HTML data into them just as easily as any other kind of data.
Well, I think there needs to be one.

You cannot presume HTML is always line based for starters.

Plain Diff does not comeup with the correct goods !

They do exist PERL has one, Python has one.

I need to code one in PHP !

Regards,

Aaron
Oct 24 '08 #5

P: n/a
"Aaron Gray" <an********@gmail.comwrote in message
news:6m************@mid.individual.net...
Hi,

I am working on an HTML WYSISYG Wiki and need to display a diff page like
WikiPedia does if two people edit a file at the same time to give the
second user the diff. Basically with additions in red and deletions in red
strike though.

There seem to be several in Perl and Python and many diff programs which
all seem to be line based and work on text written in PHP.

So I am after either existing PHP code to do an HTML diff or some help
forming an algorithm todo this.
Doing Diff's via DOM tree's look attractive. Maybe it could be done in XSLT
?

Aaron
Oct 24 '08 #6

P: n/a
"Aaron Gray" <an********@gmail.comwrote in message
news:6m************@mid.individual.net...
Hi,

I am working on an HTML WYSISYG Wiki and need to display a diff page like
WikiPedia does if two people edit a file at the same time to give the
second user the diff. Basically with additions in red and deletions in red
strike though.

There seem to be several in Perl and Python and many diff programs which
all seem to be line based and work on text written in PHP.

So I am after either existing PHP code to do an HTML diff or some help
forming an algorithm todo this.
I have been looking into using XHTML/XML and DOM, this gives the tree
walking mechanism, but the actual diff still looks difficult :)

Aaron
Oct 24 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.