Jump to content

[SOLVED] search tag highlighter


DeanWhitehouse

Recommended Posts

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 :D

Link to comment
https://forums.phpfreaks.com/topic/136130-solved-search-tag-highlighter/
Share on other sites

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);
?>

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

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.

Archived

This topic is now archived and is closed to further replies.

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