Page 1 of 1
matching any character including white space characters...
Posted: Thu Mar 15, 2007 1:37 pm
by Dave2000
Code: Select all
function bb_code($text)
{
$bbcode_to_from = array(
'/\[b\](.+)\[\/b\]/i' => '<b>$1</b>',
);
foreach ($bbcode_to_from AS $from => $to)
{
$text = preg_replace($from, $to, $text);
}
return $text;
}
$text = '[b]hel
lo[/b]';
Echo = bb_code($text);
The above example wont work. Despite a "." supposedly representing
any character, i eventually found out it doesn't represent white space characters. How could i change the above to include white space characters? I have tried many things, like...
but none seem to work

Posted: Thu Mar 15, 2007 2:11 pm
by Kieran Huggins
Posted: Thu Mar 15, 2007 2:32 pm
by Dave2000
Hi Kieran. That doesn't work

I also tried it with the + outside the square brackets

Posted: Thu Mar 15, 2007 3:01 pm
by Kieran Huggins
I think what you're probably looking for is:
...then $1 will be the inner-text.
Check out:
http://www.cuneytyilmaz.com/prog/jrx/
Posted: Thu Mar 15, 2007 10:38 pm
by feyd
Ahem. "." represents white-space characters. It does not, without modification, match new-line characters because the default action is on a per line basis.
The DOT_ALL flag or "s" pattern modifier may be of interest.
Posted: Fri Mar 16, 2007 10:24 am
by Dave2000
The "s" modifier does the trick nicely. Thank you

Posted: Fri Mar 16, 2007 1:51 pm
by Kieran Huggins
Nice catch feyd!