Hey,
I'm sure this is an easy one for a regex guru
This outputs:PHP Code:$string = '[b]hmmz[/b]testing[b]test[/b]';
$pattern = '/\[b\](.*)\[\/b\]/';
if(preg_match($pattern, $string, $array))
{
//$array[1] = strip_tags($array[1]);
//echo $array[1];
$string = preg_replace($pattern, '<b>\1</b>', $string);
echo $string;
}
HTML Code:<b>hmmz[/b]testing[b]test</b> [/b]
I can see why this happens, but the question is how to stop it happeningSo it matches the next closing instead of the very last!
Edit:
Hmm it seems changing the pattern to:
Fixes the problem. Why is this?PHP Code:$pattern = '/\[b\](.*?)\[\/b\]/';
Edit:
The problem with this above is it doesn't put surrounding <b></b> around the whole block tooPHP Code:$string = '[b][b]hmmz[/b]testing[b]test[/b][/b]';
$pattern = '/\[b\](.*?)\[\/b\]/';
if(preg_match_all($pattern, $string, $array))
{
//$array[1] = strip_tags($array[1]);
//echo $array[1];
$string = preg_replace($pattern, '<b>\1</b>', $string);
echo $string;
}







Bookmarks