How can PHP developers efficiently remove multiple BB codes from a text without manually listing each code to be removed?

To efficiently remove multiple BB codes from a text without manually listing each code to be removed, you can use regular expressions in PHP. By creating a pattern that matches all the BB codes you want to remove, you can use the preg_replace() function to replace them with an empty string.

$text = "Sample [b]text[/b] with [i]BB codes[/i]";
$bbCodes = array("b", "i"); // List of BB codes to remove

$pattern = "/\[(?:" . implode("|", $bbCodes) . ")\](.*?)\[\/(?:" . implode("|", $bbCodes) . ")\]/";
$cleanText = preg_replace($pattern, "", $text);

echo $cleanText; // Output: Sample text with BB codes