What are potential pitfalls when using BBCode in PHP forums?

One potential pitfall when using BBCode in PHP forums is the risk of allowing users to input malicious code that could harm the website or compromise security. To mitigate this risk, it is important to sanitize user input before processing and displaying it on the forum. This can be done by using PHP's htmlspecialchars() function to escape special characters and prevent code injection.

// Sanitize user input before processing BBCode
$userInput = htmlspecialchars($_POST['user_input']);

// Process and display BBCode
echo bbcode_to_html($userInput);