I’m still working on an online SVN tool, and got stuck again at diff calculations this time.
I have made a test file test.txt that gives me this result on diff:
Index: C:/data/aaxc/test.txt
===================================================================
--- C:/data/aaxc/test.txt (revision 8)
+++ C:/data/aaxc/test.txt (working copy)
@@ -1,3 +1,5 @@
-Fully new line
+Fully new line 1
{2nd modified line}
Specia$ čhar līne
+
+Nice one!
\ No newline at end of file
After that, I’m creating an array:
$data = explode( "\n", $svn_result );
$result = array();
for ( $k=2; $k<sizeof($data); $k++ ) {
# checks for filename
if ( substr( $data[$k], 0, 3 ) == '---' ) $result['left'] = substr( $data[$k], 4 );
else if ( substr( $data[$k], 0, 3 ) == '+++' ) $result['right'] = substr( $data[$k], 4 );
# check for changes
else if ( substr( $data[$k], 0, 1 ) == '-' ) $result['-'][] = substr( $data[$k], 1 );
else if ( substr( $data[$k], 0, 1 ) == '+' ) $result['+'][] = substr( $data[$k], 1 );
}
And the output:
Array
(
[left] => C:/data/aaxc/test.txt (revision 8)
[right] => C:/data/aaxc/test.txt (working copy)
[-] => Array
(
[0] => Fully new line
)
[+] => Array
(
[0] => Fully new line 1
[1] =>
[2] => Nice one!
)
)
So far so good, but how can I now make sure witch line has been changed and to what? Because currently, when I try to highlight the changes, I can’t in no way be sure that it will hightlight it correctly.
Maybe there is a script that already does this?

Currently it is working fine on small changes, but will definitely fail on big ones.
You’ll need to store the line positions that are given on the 5th line of the diff, the one beginning with
@@.So you could do:
Which will give you output like:
And then when you loop through the
$resultarray you will know which line changes have been made on by the index key: