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
Share on other sites

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.

Link to comment
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);
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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