How can one efficiently check if a Smiley is within a Code or PHP BBCode tag in PHP?

To efficiently check if a Smiley is within a Code or PHP BBCode tag in PHP, you can use regular expressions to search for the presence of the Smiley within the tags. You can create a regular expression pattern that matches the opening and closing tags, and then check if the Smiley falls within those tags.

$smiley = ":)";
$string = "[code]Hello :) World[/code]";

$pattern = '/\[code\].*?\[\/code\]|\[php\].*?\[\/php\]/s';
preg_match_all($pattern, $string, $matches);

foreach ($matches[0] as $match) {
    if (strpos($match, $smiley) !== false) {
        echo "Smiley found within tag: " . $match;
    }
}