Basic of BBCode, help please

$input = "This is *bold*";
$output = magic($input);
echo $output;                // should output "This is <b>bold</b>";

Basically how to turn [b]*[/b] into <b>*</b>? I know you can change every [b] into <b> with preg_replace(). But I’m seeking something that would seek for entire [b]fjasodisajdoiadisjdo[/b] and replace it with <b>fjasodisajdoiadisjdo</b> rather than replacing selectors one by one.

Any way to tackle this?

Short answer, regex is what you want.

There are literally thousands of articles on this and even third party libraries built purely for doing this, So i’d recommend either using one of those libraries or reading a few of the articles to find the shortcomings.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.