What are the best practices for integrating smilies in a PHP guestbook without affecting page functionality?

When integrating smilies in a PHP guestbook, it is important to ensure that the functionality of the page is not affected. One way to achieve this is by using a simple text replacement method where specific text strings representing smilies are replaced with corresponding smiley images before displaying the guestbook entries.

<?php
// Define an array of smiley text strings and their corresponding image filenames
$smilies = array(
    ':)' => 'smile.png',
    ':D' => 'laugh.png',
    ':(' => 'sad.png'
);

// Function to replace smiley text strings with corresponding image tags
function replace_smilies($text) {
    global $smilies;
    foreach($smilies as $smiley => $image) {
        $text = str_replace($smiley, '<img src="smilies/' . $image . '" alt="' . $smiley . '">', $text);
    }
    return $text;
}

// Example usage in displaying guestbook entries
$guestbook_entries = array(
    'Hello, this is my first entry :) Nice to meet you!',
    'Feeling happy today :D',
    'I am feeling a bit sad :('
);

foreach($guestbook_entries as $entry) {
    echo replace_smilies($entry) . '<br>';
}
?>