How can PHP be used to replace specific text with images in a shoutbox?

To replace specific text with images in a shoutbox using PHP, you can use the str_replace function to search for the text you want to replace and replace it with an HTML image tag.

<?php
// Sample shoutbox message
$message = "Hello everyone! :smile:";

// Define an array mapping text emoticons to image URLs
$emoticons = array(
    ":smile:" => "smile.png",
    ":sad:" => "sad.png"
);

// Replace text emoticons with images
foreach ($emoticons as $text => $image) {
    $message = str_replace($text, "<img src='$image' alt='$text'>", $message);
}

echo $message;
?>