problem with ereg_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

problem with ereg_replace

Post by winsonlee »

how can i make in such a way that after replacing the so word, all the case is remain as it is ??

Code: Select all

$out1[1] = 'the world is so So sO SO clean';
$searchword = 'so';

													$out1[1] =  ereg_replace($searchword,"<B>".$searchword."</B>",$out1[1]);
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

eregi_replace ?

It's a case insensitive function of ereg_replace
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Post by winsonlee »

i know it is incase sensitive.
but after replacing it will become
'the world is <B>so</B><B>so</B><B>so</B><B>so</B>clean';

what i want is after replacing all the case is still remain as it is which is
'the world is <B>so</B><B> So</B><B> sO</B><B> SO </B>clean';

how can i archieve that ??
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

No need to involk regular expression engine

Code: Select all

$phrase = "You should eat fruits, vegetables, and fiber every day.";
$pattern = array("fruits", "vegetables", "fiber");
$phrase = str_replace($pattern , '<b>'.$pattern.'</b>', $phrase);
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Post by winsonlee »

with the code that you provide it only applies to

$phrase = "You should eat fruits, vegetables, and fiber every day.";

it doesnt apply to phrase like

$phrase = "You should eat frUits, veGetables, and fibEr every day.";

what i want is all the words are bold in regards if the words has capital letter or not.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ereg_* is slower than snot, use preg_* (with an i pattern modifier)
Post Reply