0

I'm doing search engine for games titles in my database and I have some issue with that.

First, here's the look on DB:

ID   TITLE
1     aaB
2     abc
3     ABC
4     AbdedABc
5     deff

Next, I'm doing this query:

SELECT g.title FROM game g WHERE g.title LIKE '%abc%'

All I want to do, is to print out all titles like this (with bold matches):

abc // match
ABC // match
Abded ABc // match last part, space added for clarity

For now, my script returns this:

str_replace('abc', '<b>abc</b>', $row['title'])

abc // matches
ABC
AbdedABc

Someone know any algorithm (or other way) to do not change letters upper/lower case?

0

2 Answers 2

2

Are you looking for a case-sensitive replace then? Look at str_ireplace.

Sign up to request clarification or add additional context in comments.

Comments

1

I'm not sure what you wan't to do but to match any combination of abc in upper or lowercase and make it bold you can do like this:

 $data = "testABC";
 echo preg_replace("/(abc)/i","<bold>$1</bold>",$data);

1 Comment

I think the bold part had to do with how the OP was asking the question, not what they were trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.