nikini Posted April 19, 2007 Share Posted April 19, 2007 If anybody knows Google Docs. They have a revision history. And when you compare two docs they say what has been added and what has been removed. I've done something similar. But it's now working very good and i want to change the hall thing. So...can anybody tell me.. is there a library of some sort? I got something called inline_diff. But it's not very good. It does just word comparison and I don't need just word comparison, but also phrase comparison and paragraph comparison if case. That means that let's say if 50% of a phrase has changed then the hall phrase has changed. The same for the paragraph. Anybody know how to do that? Quote Link to comment Share on other sites More sharing options...
nikini Posted April 19, 2007 Author Share Posted April 19, 2007 Nobody knows?? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 19, 2007 Share Posted April 19, 2007 You probably want to look at the function similar_text(). Ken Quote Link to comment Share on other sites More sharing options...
nikini Posted April 19, 2007 Author Share Posted April 19, 2007 :O complexity O(N**3) that is huge. and it does it at character level. But i figured out a solution. The problem is that i want a function that fixes a html text. CAn anybody tell me how to do that? Some function that closes open tags and so on.. Quote Link to comment Share on other sites More sharing options...
Nameless12 Posted April 19, 2007 Share Posted April 19, 2007 http://au.php.net/manual/en/function.levenshtein.php quoted from php.net The complexity of the algorithm is O(m*n), where n and m are the length of str1 and str2 (rather good when compared to similar_text(), which is O(max(n,m)**3), but still expensive). Quote Link to comment Share on other sites More sharing options...
per1os Posted April 19, 2007 Share Posted April 19, 2007 :O complexity O(N**3) that is huge. and it does it at character level. But i figured out a solution. The problem is that i want a function that fixes a html text. CAn anybody tell me how to do that? Some function that closes open tags and so on.. The cleaning of HTML tags is complex in itself. Let's say I have this <html> <head> <body> <p> <div> <a> <img> How would you know where the closing </p> goes or the closing </div> goes. Does the <a> need to be closed before or after the image? That is the huge headache, for the most part you know the head should be closed before body, but what if the body tag is omitted? =) Quote Link to comment Share on other sites More sharing options...
nikini Posted April 20, 2007 Author Share Posted April 20, 2007 so basically.. it's all very complex and hard.. but still how the heck can i do it? Evem m*n is a lot as i have texts of about 5000 chars in length... Quote Link to comment Share on other sites More sharing options...
taith Posted April 20, 2007 Share Posted April 20, 2007 i have this function at home... drop me an email :-) msnmgr majikmarkr@hotmail.com or email mark@divinedesigns.ca ;-) Quote Link to comment Share on other sites More sharing options...
taith Posted April 20, 2007 Share Posted April 20, 2007 aah... found it rephrased on php.net... basically... it returns a %age of the similarity between the two strings :-) <?php function compare_strings($str1, $str2){ $count=0; $str1=ereg_replace("[^a-z]", ' ', strtolower($str1)); while(strstr($str1, ' ')) $str1 = str_replace(' ', ' ', $str1); $str1=explode(' ', $str1); $str2=ereg_replace("[^a-z]", ' ', strtolower($str2)); while(strstr($str2, ' ')) $str2 = str_replace(' ', ' ', $str2); $str2=explode(' ', $str2); if(count($str1)<count($str2)){ $tmp=$str1; $str1=$str2; $str2=$tmp; unset($tmp); } for($i=0; $i<count($str1); $i++) if(in_array($str1[$i], $str2)) $count++; return $count/count($str2)*100; } ?> Quote Link to comment Share on other sites More sharing options...
nikini Posted April 21, 2007 Author Share Posted April 21, 2007 basically... it returns a %age of the similarity between the two strings I will test it soon..But, what does that mean? Quote Link to comment Share on other sites More sharing options...
nikini Posted April 23, 2007 Author Share Posted April 23, 2007 1. The function does not work well.. I tested it like this echo compare_strings("Textul nr 1 este aici","Textul nr 2 este tot aici"); and it outputs 100. 2. It's not what i wanted..but thanks anyway.. I want users to be able to view the differences marked in green if added text or red if deleted Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 oooooooo... try this lol function find_differences($string1,$string2){ for($i=0; $i<=strlen($string2); $i++){ if($string1{$i}==$string2{$i}) $string3.='<span style="color:green;">'.$string2{$i}.'</span>'; else $string3.='<span style="color:red;">'.$string2{$i}.'</span>'; } return $string3; } it'll highlight the differences to the letter of what was changed... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.