What are some common methods for creating custom BB Codes in PHP?

One common method for creating custom BB Codes in PHP is to use regular expressions to search for specific patterns in the input text and replace them with the desired HTML code. Another approach is to create a function that takes the input text and processes it to apply the custom BB Codes before displaying it on the webpage.

function customBBCode($text) {
    $patterns = array(
        '/\[b\](.*?)\[\/b\]/is' => '<strong>$1</strong>',
        '/\[i\](.*?)\[\/i\]/is' => '<em>$1</em>',
        '/\[url\=(.*?)\](.*?)\[\/url\]/is' => '<a href="$1">$2</a>'
    );

    foreach ($patterns as $pattern => $replacement) {
        $text = preg_replace($pattern, $replacement, $text);
    }

    return $text;
}

$inputText = "[b]This[/b] is [i]custom[/i] [url=https://example.com]BB Code[/url]";
$outputText = customBBCode($inputText);

echo $outputText;