title: Php preg_replace with array in elements
body: <p>I am trying to do the emoji system and if the element in the array passes through the page, turn the value on the opposite side. Example:</p>
  
  <pre><code> $emoticons = array(
        ':)'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="smile" class="img-responsive" /&gt;',
        ':-)'   =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="smile" class="icon_smile" /&gt;',
        ':D'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="smile" class="icon_laugh" /&gt;',
        ':d'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="laugh" class="icon_laugh" /&gt;',
        ';)'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="wink" class="icon_wink" /&gt;',
        ':P'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="tounge" class="icon_tounge" /&gt;',
        ':-P'   =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="tounge" class="icon_tounge" /&gt;',
        ':-p'   =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="tounge" class="icon_tounge" /&gt;',
        ':p'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="tounge" class="icon_tounge" /&gt;',
        ':('    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="sad face" class="icon_sad" /&gt;',
        ':o'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="shock" class="icon_shock" /&gt;',
        ':O'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="shock" class="icon_shock" /&gt;',
        ':0'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="shock" class="icon_shack" /&gt;',
        ':|'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="straight face" class="icon_straight" /&gt;',
        ':-|'   =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="straight face" class="icon_straight" /&gt;',
        ':/'    =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="straight face" class="icon_straight" /&gt;',
        ':-/'   =&gt;  '&lt;img src="assets/smiles/smilesblank.png" alt="straight face" class="icon_straight" /&gt;'
   );
   foreach($emoticons as $icon =&gt; $image) {
        $icon = preg_quote($icon);
        $text = preg_replace("~\b$icon\b~",$image,$text);
   }
  </code></pre>