DeanWhitehouse Posted December 8, 2008 Share Posted December 8, 2008 At the moment i am using this code to replace any words with highlighted ones that are searched for, but at the moment this will change the words to the one that was searched (normally in lower case). How can i have it keep the original word. e.g searched the word: "test" it will show the tag as "test" even if it is saved as "TeSt" <?php $tags = $rows['tags']; $tags = str_replace(","," ",$tags); $tags = str_ireplace($search,"<b style=\"color:#0000FF;\">".$search."</b>",$tags); $title = ucfirst($rows['title']); $title = str_ireplace($search,"<b style=\"color:#0000FF;\">".$search."</b>",$title); ?> This doesn't make much sense, but hopefully you understand Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/ Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 Not sure if this would work but: <?php preg_replace("/" . $search . "/i", "<b style=\"color:#0000FF;\">$1</b>",$title); ?> Not 100% sure but looking into the preg_replace you can actually call what was found using the $1 etc. Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-709932 Share on other sites More sharing options...
DeanWhitehouse Posted December 8, 2008 Author Share Posted December 8, 2008 Using $tags = preg_replace("/" . $search . "/", "<b style=\"color:#0000FF;\">$1</b>",$tags); This doesn't do anything, it just shows the tag normally Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-709943 Share on other sites More sharing options...
DeanWhitehouse Posted December 8, 2008 Author Share Posted December 8, 2008 Also how can i remove duplicate words from an array. i have tried <?php $tags = make_safe($_POST['tags']); $tag = explode(",",$tags); foreach($tag as $t) { if(substr_count(strtolower($tags),strtolower($t)) > 1) { $dup[] = $t; } } foreach($dup as $dupilcate) { if(substr_count(strtolower($tags),strtolower($dupilcate)) > 1) { //echo $t."<Br>"; $pos = stripos($tags,$dupilcate); $len = strlen($dupilcate); $ta = substr_replace($tags,"",$pos,$len); } } print_r($ta); ?> Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-709974 Share on other sites More sharing options...
DeanWhitehouse Posted December 8, 2008 Author Share Posted December 8, 2008 Haha <?php $tags = make_safe($_POST['tags']); $tags = explode(",",$tags); $tags = array_unique($tags); $tags = implode(",",$tags); echo $tags; ?> Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-709992 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 Nice, glad you got it working and posted the example =) I guess I mis-understood the question, I was under the impression that you were parsing text in like a blog or essay form and highlighting that.... Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-710053 Share on other sites More sharing options...
DeanWhitehouse Posted December 8, 2008 Author Share Posted December 8, 2008 That code i just posted was removing duplicate tags, i still haven't got $tags = preg_replace("/" . $search . "/", "<b style=\"color:#0000FF;\">$1</b>",$tags); working And here is the page using it http://djw-webdesign.awardspace.com/search.php Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-710056 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 That code i just posted was removing duplicate tags, i still haven't got $tags = preg_replace("/" . $search . "/", "<b style=\"color:#0000FF;\">$1</b>",$tags); working And here is the page using it http://djw-webdesign.awardspace.com/search.php I should have some time in a little while I will work on my regex and get it goin for ya. Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-710062 Share on other sites More sharing options...
DeanWhitehouse Posted December 8, 2008 Author Share Posted December 8, 2008 thanks i tried $tags = preg_replace("/" . $search . "/", "<b style=\"color:#0000FF;\">\\1</b>",$tags); but no luck, and a few other variations Quote Link to comment https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/#findComment-710064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.