What is the best approach to integrating smiles into a PHP chat?

To integrate smiles into a PHP chat, you can create a function that replaces specific smiley symbols with corresponding image tags. You can store the mapping of smiley symbols to image URLs in an array for easy reference. Then, use the str_replace function to replace the smiley symbols with image tags in the chat messages before displaying them.

function addSmiles($message) {
    $smileys = array(
        ':)' => '<img src="smile.png" alt=":)" />',
        ':(' => '<img src="sad.png" alt=":(" />',
        ':D' => '<img src="laugh.png" alt=":D" />'
    );
    
    foreach($smileys as $smiley => $img) {
        $message = str_replace($smiley, $img, $message);
    }
    
    return $message;
}

// Example usage
$chatMessage = "Hello there! :)";
echo addSmiles($chatMessage);