/ Published in: PHP
Released into the public domain. Can be a little buggy, can break up HTML (you may wish to remove HTML before running text through this function).
Expand |
Embed | Plain Text
function label_words($text) { for($i=0;$i<count($words);$i++) { $times_labeled[$words[$i]]++;// = $times_labeled[$words[$i]]++; else $times_labeled[$words[$i]] = 0; $new_words[$times_labeled[$words[$i]] . '_' . $words[$i]] = ''; } return $new_words; } function diff($text1, $text2) { $text1_words = label_words($text1); $text2_words = label_words($text2); $added_words = array_diff_key($text2_words, $text1_words); $removed_words = array_diff_key($text1_words, $text2_words); $text1_output = ''; foreach($text1_words as $text1_word => $empty) { $text1_output .= isset($removed_words[$text1_word]) ? "<del>$original_word</del> " : "$original_word "; } $text2_output = ''; foreach($text2_words as $text2_word => $empty) { $text2_output .= isset($added_words[$text2_word]) ? "<ins>$original_word</ins> " : "$original_word "; } }
You need to login to post a comment.
