In fact, my question concerns an algorithm. I need to be able to attach annotations to certain parts of a text, like a word or a group of words. The first thing that came to me to do so is to store the position of this part (indexes) in the text.
Fo开发者_JAVA技巧r instance, in the text 'The quick brown fox jumps over the lazy dog', I'd like to attach an annotation to 'quick brown fox', so the indexes of the annotation would be 4 - 14.
But since the text is editable (other annotations could provoke a modification from text's author), the annoted part is likely to move (the indexes could change). In fact, I don't know how to update the indexes of the annoted part.
What if the text becomes 'Everyday, the quick brown fox jumps over the lazy dog' ?
I guess I have to watch every change of the text in the front-end application ?
The front-end part of the application will be HTML with Javascript. I will be using PHP to develop the back-end part and every text and annotation will be stored in a database.
You have to mark the position of the text with a marker. Say, in your example write to the database the following:
The quick brown fox&1 jumps over the lazy dog
and write your annotation in the proper table with primary key 1. While retrieving a record from DB you have to parse it and show annotation instead of a marker &1.
The only problem is to select a proper marker. For sure, & is a bad choice.
精彩评论