Comparing strings that contain html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Comparing strings that contain html

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

I tried strip tags along with trim and when using

Code: Select all

similar_text()
to compare the two strings it only says they are 85% similar even though they look identical when I echo them out in browser?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's likely whitespace differences.
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply