PHP – Generate Automatic Smileys

December 29th, 2012 by Laeeq | No comments

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. ?>

Output:

smilies example

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • How much memory do PHP variables use?
  • Manipulating PHP arrays: push, pop, shift, unshift
  • 10 Super Useful PHP Code Snippets
  • Let’s play with php.ini file Configuration
  • 15+ regular expressions for PHP developers
  •  

     

    1. No comments yet.
    1. No trackbacks yet.