How can Smilies be inserted using PHP in a News system?

To insert smilies using PHP in a news system, you can create a function that replaces specific text strings (e.g. ":)") with corresponding smiley images. You can store the mapping of text strings to image URLs in an array and use str_replace() function to replace the text with images in the news content.

<?php
function insertSmilies($content) {
    $smilies = array(
        ':)' => 'smile.png',
        ':(' => 'sad.png',
        ':D' => 'laugh.png'
    );

    foreach ($smilies as $smiley => $image) {
        $content = str_replace($smiley, '<img src="smilies/'.$image.'" alt="'.$smiley.'">', $content);
    }

    return $content;
}

$newsContent = "This is a news article with a :) and a :D";
$newsContentWithSmilies = insertSmilies($newsContent);
echo $newsContentWithSmilies;
?>