Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.