[solved] ereg_replace - multiple instances....
Posted: Fri Aug 19, 2005 7:24 pm
Hi there,
I have been trying to solve my problem for a few hours now. I must be making a stupid mistake, I guess.....
I want the following text:
to be replaced to
I use the following code:
(spaces in [:graph :] and [:spaces :] are intentionally, they are not in my code.)
But what happens than is that it takes the FIRST match of [ b ] and the LAST match of [ /b ] resulting in:
My question is: what pattern should I use to make the ereg_replace function look for the SMALLEST possible match(es)? And thereby replacing BOTH my instances of the pattern? And not just the biggest possible match.
Any help on this matter is highly appreciated!
I have been trying to solve my problem for a few hours now. I must be making a stupid mistake, I guess.....
I want the following text:
Code: Select all
This [b]is[/b] just [b]an example[/b] of a stringCode: Select all
This <b>is</b> just <b>an example</b> of a stringCode: Select all
$string = ereg_replace('\[b\]([[:graph :][:space :]]+)\[/b\]', '<b>\1</b>', $string);But what happens than is that it takes the FIRST match of [ b ] and the LAST match of [ /b ] resulting in:
Code: Select all
This <b>is[/b] just [b]an example</b> of a stringAny help on this matter is highly appreciated!