Page 1 of 1
Comparing strings that contain html
Posted: Tue May 01, 2007 8:01 am
by SmokyBarnable
I have two strings that contain html. One string is the initial unchanged string and the other string is the same string after it has been inserted in a wysiwyg editor (FCKeditor) and posted in a form. Basically I'm trying to compare the two strings to see if any changes were made. However when no changes are made I notice that the two strings are not equal. I assume this is because the editor alters the html somehow when posting the contents...even though no changes were made. So my question is how can I take two strings that contain html and strip them both down to check if they are equal or not?
Posted: Tue May 01, 2007 8:11 am
by Weirdan
Posted: Tue May 01, 2007 9:51 am
by SmokyBarnable
I tried strip tags along with trim and when using
to compare the two strings it only says they are 85% similar even though they look identical when I echo them out in browser?
Posted: Tue May 01, 2007 9:54 am
by feyd
it's likely whitespace differences.
Posted: Tue May 01, 2007 10:18 am
by SmokyBarnable
Ok I added these statements and now I can tell if any edits were made to the string by comparing it to the original.
Code: Select all
$text = strip_tags($_POST['FCKeditor1']);
$text = stripcslashes($text);
$text = ereg_replace("[^A-Za-z0-9]", "", $text);
$text=str_replace("nbsp","",$text);
This is good but what if the person doesn't change any text in the editor but does make an html change like a background or font?
Posted: Tue May 01, 2007 10:38 am
by feyd
Then you need to detect that, or better yet, stop worrying about if there was a change or not so much. If you do a simple comparison, that's enough for most.