php forum
php mysql forum
php mysql smarty
 
Topic Options
#285849 - 07/24/05 02:58 PM string search and replace
ekempter Offline
User

Registered: 10/06/01
Posts: 27
The string: I have a Green apple.<br />I want to search for the word green and highlight it.<br /><br />My code (where $search_word = green):<br />$textstring = eregi_replace($search_word, "<b>" . $search_word . "</b>", $textstring);<br /><br />The result: I have a <b>green</b> apple.<br /><br />Not bad but how do I retain the original case in $textstring so that the result would be: I have a <b>Green</b> apple.<br /><br />Changing the $search_word to Green is not an option.<br /><br />Thank in advance for any assistance.

Top
#285850 - 07/26/05 06:44 AM Re: string search and replace [Re: OWL_pokemon]
Anno Offline
Code Monkey

Registered: 05/23/01
Posts: 562
Loc: Austria
Use string_replace or ereg_replace, and search once for green and once for Green.

Top
#285851 - 07/30/05 11:53 PM Re: string search and replace [Re: OWL_pokemon]
ekempter Offline
User

Registered: 10/06/01
Posts: 27
The solution:<br /><br /> $description = eregi_replace('(' . $search_word . ')', "<b>\\1</b>", $description);<br /><br />Thanks for responding Anno.

Top



Latest Posts
[7.2.1] - Naked shoutbox
by bellaonline
05/05/12 05:00 PM
[7.x] Stop Forum Spam Integration v0.4
by bellaonline
05/05/12 03:53 PM
Shout Box

(Views)Popular Topics
Known public proxy servers 1689885
Integrated Index Page (IIP) 5.3.1 555705
Finished-[6.5.2] Games Arcade Deluxe v1.9 501236
Integrated Index Page (IIP) 5.1.1 415112
TLD Bv2.1 Released - Threads Links Directory 396822
[6.0x] Who's Online 4.0.0 [Finished] 389412
Finished-[6.5.1] Integrated Index Page (IIP) 6.5 330423
Q & A 298663
Slash UBB 266936
[6.3.x] [beta] Hit Hack 2.0 227970
Forum Stats
13621 Members
59 Forums
37191 Topics
295716 Posts

Max Online: 686 @ 06/28/07 07:04 AM

 

 

 
fusionbb message board php hacks