javascript - Creating an inline 'Jargon' helper in PHP -


idea:

i have article formatted in html. contains whole lot of jargon words perhaps people wouldn't understand.

i have glossary of terms (mysql table) definitions helpful there people.

i want go through html of article , find instances of these glossary terms , replace them nice javascript show 'tooltip' definition term.

i've done nearly, i'm still having problems:

  • terms being found within words (ie: aps in perhaps)
  • i have make sure doesn't alt, title, linked text, etc. text doesn't have formatting applied. needs work in tables , paragraphs.

here code have:

$query_glossary = "select word glossary_terms status = 1 order length(word) desc"; $result_glossary = mysql_query_run($query_glossary);  //reset mysql via seek don't have query again mysql_data_seek($result_glossary,0);   while($glossary = mysql_fetch_array($result_glossary)) {      //once done can replace words nice tip     $glossary_word = $glossary['word'];     $glossary_word = preg_quote($glossary_word,'/');             $article['content'] = preg_replace_callback('/[\s]('.$glossary_word.')[\s](.*?>)/i','article_checkopentag',$article['content'],10);      } 

and here php function:

function article_checkopentag($matches) {   if (strpos($matches[0], '<') === false) {     return $matches[0];   }      else {         $query_term = "select word,glossary_term_id,info glossary_terms word = '".escape($matches[1])."'";         $result_term = mysql_query_run($query_term);         $term = mysql_fetch_array($result_term);          # creating relevent link         $glossary_id = $term['glossary_term_id'];         $glossary_link = siteurl.'/glossary/term/'.string_to_url($term['word']).'-'.$term['glossary_term_id'];          # description stuff tooltip         if(strlen($term['info'])>400) {             $glossary_info = substr(strip_tags($term['info']),0,350).' ...<br /> <a href="'.$glossary_link.'">read more</a>';         }         else {             $glossary_info = $term['info'];         }           return ' <a href="javascript:;" onmouseout="untip();" class="article_jargon_highligher" onmouseover="'.tooltip_javascript('<a href="'.$glossary_link.'">'.$term['word'].'</a>',$glossary_info,400,1,0,1).'">'.$matches[1].'</a> '.$matches[2];   } } 

thank help!

move load server client. assuming "dictionary of slang" changes not , want "add nice tooltips" words across lot of articles, can export .js file , add corresponding <script> entry pages - static file cacheable web-browser.

then write client-side js-script try find dom-node "a content slang" put, parse out occurences of words dictionary , wrap them html show tooltips. js, client-side.

if method not suitable , you're going job within php backend, @ least consider caching of processed content.

i see insert description text every "jargon word" found within content. if word frequent across article? overhead. make descriptions separate, put them js object. task find words have description , mark them using short tag, instance <em>. js-script should find em`s, pick description object (associative array descriptions words) , construct tooltip dynamically on "mouse over" event.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -