function search_match($desc,$searchstr) { $searchar = explode(" ", $searchstr); $total = count($searchar)-1; for($c=0; $c <= $total; $c++) { $desc = str_replace($searchar[$c],"<b>".$searchar[$c]."</b>", $desc); } return $desc; } Code (markup): Anyone know how to make this where it will replace it and be non case sensitive? I do a word search for ms swan, it will not bold MS, Ms, Swan, SWan, SWAn, SWAN, etc. It will only bold the ms swan one. ---------- str_ireplace is only for php5 and I am working with php 4.3
strtolower will lower both of them. I want to leave the case alone in the original string the shown string, but just add bold around it. Thanks for the help. Still trying to figure it out.
I know it will lower both of them, But look at this: <?php $str = "rsgx gfsd MS SwAn kjh"; $search = "ms swan"; $searchLen = strlen($search); $where = stripos($str, $search); $theSame = substr($str, $where, $searchLen); $desc = str_replace($theSame,"<b>".$theSame."</b>", $str); ?> PHP: $str == $desc . It's the same string, but "ms swan" is bold. Emm...Here is the full function: <?php function search_match($str,$search) { $search = strtolower($search); $searchLen = strlen($search); $where = stripos($str, $search); $theSame = substr($str, $where, $searchLen); $desc = str_replace($theSame,"<b>".$theSame."</b>", $str); return $desc; } ?> PHP:
I read somewhere that it was supported on PHP4. You could always use http://uk3.php.net/manual/en/function.eregi-replace.php
lfhost: hrm.. thanks! I think this might work.. <?php $pattern = '(>[^<]*)('. quotemeta($_GET['search']) .')'; $replacement = '\\1<span class="search">\\2</span>'; $body = eregi_replace($pattern, $replacement, $body); ?> Code (markup): Will have to modify it a bit, but I get the jest of it.