text - Horde_Text_Diff string comparison library only comparing 1st character of strings -
i using horde_text_diff compute difference between 2 strings. sample code follows:
$check_diff = new horde_text_diff( 'auto', array('asdf','asd11') ); $renderer = new horde_text_diff_renderer_inline(); echo $renderer->render($check_diff);
this echoes nothing. correct behaviour show difference @ character 4.
if change comparison array array('asdf','asd11') to, instance, array('asdf','12345'), output a1. in other words, seems comparing first character. ideas?
when try this, 2 warnings:
php warning: array_walk() expects parameter 1 array, string given in /usr/share/php/horde/text/diff/engine/native.php on line 33 php warning: array_walk() expects parameter 1 array, string given in /usr/share/php/horde/text/diff/engine/native.php on line 34
i.e., getting strings expects arrays.
that's because, rather passing (an array containing) 2 strings horde_text_diff(), should pass (an array containing) 2 arrays-of-strings (where each string represents line of text).
if actual strings you're trying pass in contain multiple lines of text, can split them arrays-of-strings using explode(), e.g.:
$a = "foo\nbar\nbaz"; $b = "foo\nqux\nbaz"; $a_lines = explode("\n", $a); $b_lines = explode("\n", $b); $check_diff = new horde_text_diff( 'auto', array($a_lines, $b_lines) ); $renderer = new horde_text_diff_renderer_inline(); echo $renderer->render($check_diff);
which outputs:
foo <del>bar</del><ins>qux</ins> baz
Comments
Post a Comment