title: How to replace the <img> tag/s present in an string with another string that represents some code in PHP?
body: <p>I've one following string:</p>
  
  <pre><code>$feed_status = Nice &lt;img src=\"http://52.1.47.143/file/pic/emoticon/default/smile.png\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" /&gt; to see &lt;img src=\"http://52.1.47.143/file/pic/emoticon/default/happy.png\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" /&gt; you all back again &lt;img src=\"http://52.1.47.143/file/pic/emoticon/default/tongue.png\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" /&gt;;
  </code></pre>
  
  <p>I've another array titled <code>$emoticon_codes</code> containing three elements which needs to be placed in above string in place of those <code>&lt;img&gt;</code> tags.</p>
  
  <pre><code>Array
  (
      [0] =&gt; \ue056
      [1] =&gt; \ue057
      [2] =&gt; \ue105
  )
  </code></pre>
  
  <p>The three <code>&lt;img&gt;</code> tags from the string should be replaced by the above three strings in same order. </p>
  
  <p>How should I achieve this in an optimum way?</p>
  
  <p>Please help me. Thanks in advance. </p>
  
  <p>My final string should be like this after printing :</p>
  
  <p><strong>Nice \ue056 to see \ue057 you all back again \ue105;</strong></p>
  
  <p>I TRIED FOLLOWING THING :</p>
  
  <pre><code>$doc = new DOMDocument();
        $doc-&gt;loadHTML($feed_status);
        $imageTags = $doc-&gt;getElementsByTagName('img');
        if(count($imageTags)) {
          $emoticon_codes = array();
          foreach($imageTags as $tag) {
            /*echo basename($tag-&gt;getAttribute('src'));
            echo "&lt;br&gt;";*/
            if (basename($tag-&gt;getAttribute('src')) == 'evilgrin.png') {
              array_push($emoticon_codes, '\ue404');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'grin.png') {
              array_push($emoticon_codes, '\ue415');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'happy.png') {
              array_push($emoticon_codes, '\ue057');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'smile.png') {
              array_push($emoticon_codes, '\ue056');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'surprised.png') {
              array_push($emoticon_codes, '\ue107');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'tongue.png') {
              array_push($emoticon_codes, '\ue105');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'unhappy.png') {
              array_push($emoticon_codes, '\ue403');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'waii.png') {
              array_push($emoticon_codes, '\ue407');
            }
            if (basename($tag-&gt;getAttribute('src')) == 'wink.png') {
              array_push($emoticon_codes, '\ue405');
            }
          }
        }
  </code></pre>