title: A better way to replace emoticons in PHP?
body: <p>Right now I am using this function for emoticons:</p>
  
  <pre><code>function emoticons($text) {
          $icons = array(
                  ':)'    =&gt;  '&lt;img src="/images/blank.gif" alt="smile" class="icon_smile" /&gt;',
                  ':-)'   =&gt;  '&lt;img src="/images/blank.gif" alt="smile" class="icon_smile" /&gt;',
                  ':D'    =&gt;  '&lt;img src="/images/blank.gif" alt="smile" class="icon_laugh" /&gt;',
                  ':d'    =&gt;  '&lt;img src="/images/blank.gif" alt="laugh" class="icon_laugh" /&gt;',
                  ';)'    =&gt;  '&lt;img src="/images/blank.gif" alt="wink" class="icon_wink" /&gt;',
                  ':P'    =&gt;  '&lt;img src="/images/blank.gif" alt="tounge" class="icon_tounge" /&gt;',
                  ':-P'   =&gt;  '&lt;img src="/images/blank.gif" alt="tounge" class="icon_tounge" /&gt;',
                  ':-p'   =&gt;  '&lt;img src="/images/blank.gif" alt="tounge" class="icon_tounge" /&gt;',
                  ':p'    =&gt;  '&lt;img src="/images/blank.gif" alt="tounge" class="icon_tounge" /&gt;',
                  ':('    =&gt;  '&lt;img src="/images/blank.gif" alt="sad face" class="icon_sad" /&gt;',
                  ':o'    =&gt;  '&lt;img src="/images/blank.gif" alt="shock" class="icon_shock" /&gt;',
                  ':O'    =&gt;  '&lt;img src="/images/blank.gif" alt="shock" class="icon_shock" /&gt;',
                  ':0'    =&gt;  '&lt;img src="/images/blank.gif" alt="shock" class="icon_shack" /&gt;',
                  ':|'    =&gt;  '&lt;img src="/images/blank.gif" alt="straight face" class="icon_straight" /&gt;',
                  ':-|'   =&gt;  '&lt;img src="/images/blank.gif" alt="straight face" class="icon_straight" /&gt;',
                  ':/'    =&gt;  '&lt;img src="/images/blank.gif" alt="straight face" class="icon_straight" /&gt;',
                  ':-/'   =&gt;  '&lt;img src="/images/blank.gif" alt="straight face" class="icon_straight" /&gt;'
          );
          return strtr($text, $icons);
      }
  </code></pre>
  
  <p>But if you enter a link the <code>:/</code> part of <code>http://</code> gets replaced: </p>
  
  <p><img src="https://i.stack.imgur.com/LzW19.png" alt="enter image description here"></p>
  
  <p>Same with code (4 spaces in front of each line to create code box), but for some reason a simple <code>)</code> gets replaced (with a wink) as well:</p>
  
  <p><img src="https://i.stack.imgur.com/FseYU.png" alt="enter image description here"></p>
  
  <p>Is there a better solution to this than replacing all of the icons like this? It obviously doesn't work good. I have searched on Google a lot and haven't found any better way. I also tried putting a space before each emoticon in the associative array above but that doesn't work if you just enter a :) without anything before it. </p>