Jump to content

bbcode


doddsey_65

Recommended Posts

Do you mean add bbcode tags (eg ) when the user clicks a button? For this you'll want to use javascript

 

Or to parse bold to bold?

For parsing bbcode you'd use regex

$str = 'This is some [b]text[/b], bold and [b][u]underlined[/u][/b]

[i]italics[/i], [b]bold[/b], [u]underline[/u]';

$str = preg_replace('~\[b\](.*?)\[/b\]~', '<b>\\1</b>', $str);
$str = preg_replace('~\[i\](.*?)\[/i\]~', '<u>\\1</u>', $str);
$str = preg_replace('~\[u\](.*?)\[/u\]~', '<u>\\1</u>', $str);

echo nl2br($str);

Link to comment
https://forums.phpfreaks.com/topic/212595-bbcode/#findComment-1107503
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.