Skip to main content

PHP – Generate Automatic Smileys

We are very much familiar with smileys on Gmail and Facebook chat. We often express our emotions by pressing shift-colon and shift-backquote like “:)” during chat with our friends which displays a smiley images in place of characters. Below is complete PHP example code which allows you to automatically replace a smiley symbol character by a smiley image.

  1. <?php
  2. $texte=‘A text message with a smiley :-)’;
  3. echo str_replace(‘:-)’,‘<img src=”images/psmilies.png”>’,$texte);
  4. ?>


smilies example

Leave a Reply

Your email address will not be published. Required fields are marked *


Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!