How to make every word in the text clickable and send it to a script

I have text like

"The fast brown fox jumps over the lazy dog. The fast brown fox jumps over the lazy dog. The fast brown fox jumps over the lazy dog. The fast brown fox jumps

over a lazy dog. "

When I click on a word, I have to get data from XML or from mysql about this word.

How can I make each word clickable and send it to another script

for example: I click on a dog, and in a new window do I get information about the dog? about the fox about the fox? each word should be interactive

Any ideas, links or examples?

Using php, mysql, jquery, ajax

+7
jquery xml ajax php mysql
source share
2 answers

Wrap each word in its own space, possibly with a CSS class, to distinguish them as “word spacing”. Add a hover handler for all spaces with this class, which extracts the contents and executes an ajax request to get the data associated with this word. If you return some data, you will see a DIV (“tooltip”) containing information that is tied to the location of the mouse and has a z-index that allows it to navigate the rest of the content. When the mouse is not over the range, remove the associated "tip".

There are many jQuery hint plugins that you can easily adapt to this requirement.

<span class="word">the</span> <span class="word">quick</span> ... // use a ficticious tooltip plugin that uses gettip.php and passes // the content of the DOM element as a parameter $('span.word').tooltip({ url: '/gettip.php' }); 

NOTE. You probably want to do this only for the words of interest, and not for every word on the page. That is, there is a dictionary of words that require tooltips, and only wrap these words on the page that exist in the dictionary. There is little point (unless it is a grammar application) to do this with every possible word.

+8
source share

Too many questions in one. I would answer one of the names. Suppose you define a word as a group of characters separated by spaces. So you can use the explode() function and get an array of words

Now you can iterate over the array and print it in any way:

 $string = "The quick brown fox jumps over the lazy dog"; $array = explode(" ",$string); foreach ($array as $word) { $eword=urlencode($word); echo "<a href=getinfo.php?word=$eword>$word</a> "; } 

So, you will have your links, and now you need to get a php / mysql beginner's book to learn how to write the rest.

+1
source share

All Articles