EllisLab text mark
Advanced Search
     
How to compare changes in database
Posted: 01 December 2011 03:12 PM
Avatar
Joined: 2011-03-25
220 posts

Hey guys,

I am wondering what is the best way to compare a string with what is in the database.

Example (Before I go further, let’s just say I’m thinking of a wiki edit style)

Let’s say I pull a description from my database, and put it in a <textarea>. The user submits this with a change. And to make it a bit more complicated, this edit is in the middle of a string.

So the user changes:
“Codeigniter is a free framework.”

To:
“CodeIgniter is an awesome framework.”

I would want to record the changes such as:
“Field changed… “...is a free fram…” to “...is an awesome fram…”

Or something of the sorts. I could compare the two if they’re the same, but I don’t want to make an over-complex function, or re-invent the wheel.. So how do you achieve this?

 
Posted: 01 December 2011 04:46 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
4534 posts

Maybe something like this would be easy (since you are already retrieving the original value for the person to edit)?

<input type="hidden" name="description-original" value="Here is the original description" />
<
textarea name="description">Here is the original description</textarea

Then when they submit you can just compare the two…

$description_changed = (set_value('description-original') == set_value('description')); 
 Signature 
 
Posted: 01 December 2011 05:05 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-25
220 posts

I finally found what syntax I had to use in google to get the results I want. I came across this, and will be modifying if I need be. I’ll also do some more research, but I’m liking it already.

http://paulbutler.org/archives/a-simple-diff-algorithm-in-php/

String 1:This is awesome
String 2:This really is really good man
Output:This really is [strikethrough]awesome[/strikethrough] really good man

(Seems like this forum doesn’t have anything for strikethrough..

 
Posted: 01 December 2011 05:11 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
4534 posts

Nice find there.  Not sure if it’s the reason why, but Strike is deprecated.

 Signature 
 
Posted: 01 December 2011 05:39 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-25
220 posts

a <del> wouldn’t hurt then raspberry

Just saying strikethrough so people understand it raspberry