SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Jul 22, 2001, 06:24 #1
- Join Date
- Dec 2000
- Location
- The flat edge of the world
- Posts
- 838
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can I make str_replace not case senstive?
I'm doing a simple search function, and for the results, I want to make all the bits that has the string in it bold. eg:
PHP Code:$query = cash;
$result = Cashmere;
$result = str_replace ("$query", "<b>$query</b>", "$result");
echo $result;
-
Jul 22, 2001, 06:47 #2
-
Jul 22, 2001, 10:07 #3
- Join Date
- Aug 1999
- Location
- East Lansing, MI USA
- Posts
- 12,937
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You could run a strtolower function on both parameters before doing the replacement.
Chris Beasley - I publish content and ecommerce sites.
Featured Article: Free Comprehensive SEO Guide
My Guide to Building a Successful Website
My Blog|My Webmaster Forums
-
Jul 22, 2001, 14:28 #4
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by W. Luke
If case sensitivity is needed you would have to use eregi_replace unless you built your own custom function.
Originally posted by aspen
You could run a strtolower function on both parameters before doing the replacement.
Robo, i'd just use preg_replace() which is about 2x faster than eregi_replace().
PHP Code:$query = 'cash';
$result = 'Cashmere';
$query = preg_quote($query, '/'); // only needed if your 'query' has special reg exp chars in it
$result = preg_replace("/($query)/i", '<b>$1</b>', $result);
echo $result;
Bookmarks