Jump to content

text highlight


dgnzcn

Recommended Posts

hi my highlight class is not  hightlighting in mw search results..

 

 

class highlight
    {
        public $output_text;

        function __construct($text, $words)
        {
            $split_words = explode( " " , $words );

            foreach ($split_words as $word)
            {
                $color = self::generate_colors();                
                $text = preg_replace("|($word)|Ui" , 
                           "<span style=\"background:".$color.";\"><b>$1</b></span>" , $text );
            }
            $this->output_text = $text;
        }

        private function rgbhex($red, $green, $blue)
        {
            return sprintf('#%02X%02X%02X', $red, $green, $blue);
        }

        private function generate_colors()
        {
            $red = rand( rand(60,100) , rand(200,252) );
            $green = rand( rand(60,100) , rand(200,252) );
            $blue = rand( rand(60,100) , rand(200,252) );

            $color = self::rgbhex( $red , $green , $blue );
            return $color;
        }
    }  

 

 

 

<?php $aranan = '$aranan'; 
     $renkver = new highlight ($row_Recordset1['aciklama'], $aranan);
     $ArananSonuc = $renkver ->output_text;
echo $ArananSonuc ;  
?>

Link to comment
https://forums.phpfreaks.com/topic/183879-text-highlight/
Share on other sites

My guess is that this line:

 

$aranan = '$aranan';

Is being parsed, meaning that it will replace the $aranan inside the single quotes with the variable. The variable is not yet set, and therefore it is returned as ''. Try this instead:

 

$aranan = "\$aranan";

EDIT: Never mind. Got it the wrong way round. What does the script return?

Link to comment
https://forums.phpfreaks.com/topic/183879-text-highlight/#findComment-970687
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.