0

I'm working on a search function and I'm stuck on something. I currently have the following query executed in php and displayed with simple echo:

SELECT * FROM `artist` WHERE `ArtistName` LIKE '% ".$searchfield."%'

It only selects matches that are the same in the beginning of words. For example, if someone types "a", it will return just names like "Adam" or "Jason Aldean".

What I now want to accomplish is that the searchterm is highlighted with a span or simple b tag.

I have tried doing it like this:

$display= str_ireplace($searchfield,"<b'>".$searchfield."</b>",$full);

But in this way, in my example, it will replace all the the a's in the result. What you will get then is this: J<b>a</b>son <b>A</b>lde<b>a</b>n while I just want this Jason <b>A</b>ldean. Because that's also how the query selected the row.

I hope this makes sense, I'll be happy to try any suggestions.

Thank you all in advance. - Yordi

0 Answers0