php diff example

UPDATE!

Nils Kappmeier has made a new implementaion of this script.
Less Buggs and Comments but faster ;) so dont forget to check: diff-version2.
The script can also be found in www.pmwiki.org in the module /script/phpdiff.php .

Implementation of DIFF in pure-php

Input-Data: Array
(
    [0] => <html>
    [1] => <head><title>Text</title></head>
    [2] => <body>
    [3] => code a
    [4] => code b
    [5] => code c
    [6] => code d
    [7] => code e
    [8] => code g
    [9] => </body>
    [10] => </html>
)
Array
(
    [0] => <html>
    [1] => <head><title>Text2</title></head>
    [2] => <body>
    [3] => code a
    [4] => code a
    [5] => code c
    [6] => code d
    [7] => code e
    [8] => code g
    [9] => code f
    [10] => </body>
    [11] => </html>
)

Identlical lines hidden:
1 : 1 : - <head><title>Text</title></head>
1 : 1 : + <head><title>Text2</title></head>
4 : 4 : - code b
4 : 4 : + code a
9 : 9 : + code f

Identlical lines shown:
0 : 0 : = <html>
1 : 1 : - <head><title>Text</title></head>
1 : 1 : + <head><title>Text2</title></head>
2 : 2 : = <body>
3 : 3 : = code a
4 : 4 : - code b
4 : 4 : + code a
5 : 5 : = code c
6 : 6 : = code d
7 : 7 : = code e
8 : 8 : = code g
9 : 9 : + code f
9 : 10 : = </body>
10 : 11 : = </html>

Compared: array_diff( $f1, $f2 );
Array ( [1] => <head><title>Text</title></head> [4] => code b )
Compared: array_diff( $f2, $f1 );
Array ( [1] => <head><title>Text2</title></head> [9] => code f )

© 2007 Daniel Unterberger.Ayurveda.AyurMedia Projekte view source .ayurmedia  Yoga Expo 2010