title: How to real time replace text with emoticons in my php comment box
body: <p>In my comment box I want to If user write :) or :( or something like any emotion in textarea, It replace emoticon just after click on space key.</p>
  
  <p>So, how to real time replace my text to emoticons. </p>
  
  <p>my php code: which replace emoticon after submit.</p>
  
  <pre><code>function smileys($text){
  // Smiley to image
  $smileys = array(
      ':)' =&gt; '&lt;img src="smilies/smile.gif" border="0" alt="" /&gt;',
      ':D' =&gt; '&lt;img src="smilies/smile.gif" border="0" alt="" /&gt;',
      ':(' =&gt; '&lt;img src="smilies/sad.gif" border="0" alt="" /&gt;',
  );
  
  // Now you need find and replace
  foreach($smileys as $search =&gt; $replace){
       $text = preg_replace("#(?&lt;=\s|^)" . preg_quote($search) . "#", $replace, $text);
  return $text;
      }
  }
  
  echo''.smileys($description).'';
  </code></pre>