<?php
	if (isset($_GET['search'])) {
		$string = (stripslashes($row[3])); 
		$search_string = str_replace("".$_GET['search']."", "<span class=\"search_highlight\">".$_GET['search']."</span>", "".$string."");
		echo $search_string;
	}
	else {
		echo print "".stripslashes($row[3]).""; 
	}
?>

I have this script and it kinda works how i want except when the value is not exactly the same, such as if the value of $_GET['search'] is "Hello" but the value in the $string is "hello" it wont replace it. I would like it do work case insensitive so that if it is "Hello", "HELLO", or "hello" it will always replace with "<span class=\"search_highlight\">Hello</span>", "<span class=\"search_highlight\">HELLO</span>" , or "<span class=\"search_highlight\">hello</span>". Any ideas how do go about doing this?.

    <?php
    		if (isset($_GET['search'])) {
    			$string = (stripslashes($row[3])); 
    			$search_string = preg_replace("/".$_GET['search']."/i", "<span class=\"search_highlight\">".$_GET['search']."</span>", "".$string."");
    			echo $search_string;
    		}
    		else {
    			echo print "".stripslashes($row[3]).""; 
    		}
    		?>

    I have it doing a case insensitive replace now but i would like it to keep the case of the original if possible.

      $search_string = preg_replace("/".preg_quote($_GET['search'], '/')."/i", 
            "<span class=\"search_highlight\">".$0."</span>", $string);
      
        Write a Reply...