note 74071 deleted from function.str-replace by felipe

From: Date: Sun, 23 Mar 2008 23:05:33 +0000
Subject: note 74071 deleted from function.str-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137422@lists.php.net to get a copy of this message
Note Submitter: patrick at rocksolidsystems dot biz ---- With reference to the google type searches above ... This is a case insensitive replace.... This code below will highlight the "found" text in red and return the string unaltered (in terms of case). <?php function turn_red($haystack,$needle) { $h=strtoupper($haystack); $n=strtoupper($needle); $pos=strpos($h,$n); if ($pos !== false) { $var=substr($haystack,0,$pos)."<font color='red'>".substr($haystack,$pos,strlen($needle))."</font>"; $var.=substr($haystack,($pos+strlen($needle))); $haystack=$var; } return $haystack; } ?>

« previous php.notes (#137422) next »