Thread: Forum
View Single Post
Old 01-08-2008, 08:09 PM   #25 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

I actually wrote a class for BB code, but I don't think Karl'd appreciate me handing it out, unfortunately. The following should give you a good idea. It does the bold, italic and underline for you:

PHP Code:
$szText 'This is [u]a[/u] [b]test for bold[/b].';

$szText preg_replace('~\[b\](.+?)\[/b\]~i''<b>\\1</b>'$szText);
$szText preg_replace('~\[i\](.+?)\[/i\]~i''<i>\\1</i>'$szText);
$szText preg_replace('~\[u\](.+?)\[/u\]~i''<u>\\1</u>'$szText);

echo 
$szText
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote