Page 1 of 1

problem with ereg_replace

Posted: Sun Oct 16, 2005 2:52 am
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]);

Posted: Sun Oct 16, 2005 5:45 am
by s.dot
eregi_replace ?

It's a case insensitive function of ereg_replace

Posted: Sun Oct 16, 2005 6:38 am
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 ??

Posted: Sun Oct 16, 2005 10:18 am
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);

Posted: Sun Oct 16, 2005 8:11 pm
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.

Posted: Sun Oct 16, 2005 8:20 pm
by feyd
ereg_* is slower than snot, use preg_* (with an i pattern modifier)