Skip to content
PHP Logo

What parameters need to be added to the preg_replace function to properly highlight content in bbcode?

When using the preg_replace function to highlight content in bbcode, you need to add the 'i' parameter to make the pattern matching case-insensitive. This ensures that the content is properly highlighted regardless of the case of the tags in the bbcode. Additionally, you should also use the 's' parameter to allow the dot (.) metacharacter to match newline characters, which may be present in the content.

php
$bbcode = "[b]This is bold text[/b]";
$highlighted_bbcode = preg_replace('/\[b\](.*?)\[\/b\]/is', '<strong>$1</strong>', $bbcode);
echo $highlighted_bbcode;