View Single Post
  #1 (permalink)  
Old 06-23-09, 04:57 PM
myklt myklt is offline
Newbie Coder
 
Join Date: Feb 2009
Location: UK
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Help with using preg_replace

I am having problems with finishing a function I have made which uses PHP's preg_replace.

The function runs through text within a forum I am designing to highlight target words to the user based on their interests etc I am hoping to allow a customizable tool-tip to pop-up over the highlighted areas to give the user extra information/ links etc.

The function is highlighting the words 100% and my tooltip is displaying the way I want it atm BUT the problem I am having is getting the PHP variable $definition to output its content instead of "$definition".

The problem seems to be the method I am trying to output a variable within a String. I have exausted every way I know of doing this and would like help. I have tried using <?php echo "$definition"?>, ".$definition.", print $definition, echo $definition....

Does anyone know any way or method to get the output of $definition to populate the tooltips?

PHP Code:

function getTargetWords($fContent){

....
.... 
....

/***Definition***/
       
$definition "Definition text for inside the tooltip";

/***!!!!!!!!To be fixed to output tooltip definition not "$definition" !!!!!!!!!***/        
       
$replace '<a href="#"><span class="highlight_word">\1<span class="tooltip">$definition</span></span></a>';
                
 
/*** highlight the words ***/
         
$fContent preg_replace("/\b($word)\b/i"$replace$fContent);
....
....
....

any help will be appreciated, thanks
Reply With Quote