What is the recommended approach for adding smilies in PHP code for display in the frontend?

When adding smilies in PHP code for display in the frontend, it is recommended to use a combination of HTML entities and CSS styles to ensure proper rendering across different browsers and devices. One approach is to define a mapping of smilies to their corresponding HTML entities and then apply CSS styles to display them as images.

<?php
// Define an array mapping smilies to their corresponding HTML entities
$smilies = array(
    ':)' => '🙂', // Smiling face
    ':D' => '😀', // Grinning face
    ':(' => '🙁', // Frowning face
);

// Function to replace smilies with HTML entities
function replaceSmilies($text) {
    global $smilies;
    return strtr($text, $smilies);
}

// Example text with smilies
$text = 'Hello, how are you? :)';

// Display text with smilies
echo '<p>' . replaceSmilies($text) . '</p>';
?>