Home

or
will mess things up unless Purified – and if it is Purified, then the displayed string will be incorrect anyway. $output_div_style = “border: solid #000000 1px; padding: 2%; word-wrap: break-word; white-space: normal;”; include_once(‘HTMLPurifier.auto.php’); $purifier = new HTMLPurifier(); # Must stripslashes() because WordPress escapes all server variables in wp-settings.php with add_magic_quotes() $string1 = stripslashes($_POST[‘string1’]); $string2 = stripslashes($_POST[‘string2’]); /* # Need [ Do autoformatting of line breaks – i.e. use nl2br() function] below $do_nl2br = $_POST[‘do_nl2br’]; if($do_nl2br) { $string1 = nl2br($string1); $string2 = nl2br($string2); }*/ $lines1 = explode(“\n”, $string1); $lines2 = explode(“\n”, $string2); #Do not use if(count($lines1) OR count($lines2)), because if explode is passed an empty string, it will return an array containing that string if(strlen($string1) OR strlen($string2)) { $diff = &new Text_Diff($lines1, $lines2); $renderer = &new Text_Diff_Renderer_inline(); $diff_string = $renderer->render($diff); $renderer_unified = &new Text_Diff_Renderer_unified(); # Note: Text_Diff_Renderer_unified() doesn’t seem to escape HTML, so use htmlspecialchars() on what it returns $diff_string_unified = htmlspecialchars($renderer_unified->render($diff)); $clean_html = $purifier->purify($diff_string); $clean_html_unified = $purifier->purify($diff_string_unified); $diff_output = “

Text Comparison Result – How the 2nd string was different

\n”; if(strlen($diff_string)) { $diff_output .= “
Green text indicates additional text that is new in the second string, red text indicates deleted text that was no longer present in the second string.
\n”; $clean_html_colored; $clean_html_colored = str_replace(array(““, ““, ““, ““), array(““, ““, ““, ““), $clean_html); $diff_output .= “
\n”.nl2br($clean_html_colored).”\n
\n”; $diff_output .= “\n

Alternative Representation

\n
underline indicates additional text that is new in the second string, strikethru indicates deleted text that was no longer present in the second string.
\n”; $diff_output .= “
\n”.nl2br($clean_html).”\n
\n”; $diff_output .= “\n

Unified Representation

\n
A + (plus sign) prefix indicates added text, a (minus sign) prefix indicates removed text, and no prefix indicates unchanged text.
\n”; $diff_output .= “
\n”.nl2br($clean_html_unified).”\n
\n”; } else { $diff_output .= “

The two strings were the same.“; } echo $diff_output; } ?>

Input Comparison String 1

Input Comparison String 2