title: Replace string with image
body: <p>I'm looking for a way to replace certain strings with an image.  All strings are enclosed in {} and when the code sees the [} what's inside will be read and what it equals will become the specific image. I haven't the foggiest how to implement this and was hoping someone could give me an example.</p>
  
  <p>Here's my example to better explain:</p>
  
  <pre><code>{1} is replaced with an image
  </code></pre>
  
  <p>So, when the code sees the {} it will activate. Now so it does not interfere with other parts of the code it is limited to 1 character and only certain characters. This is for magic card casting costs to be more specific. So it would be limited too.....</p>
  
  <p>B,U,R,G,W,X,T, 1-99 for example</p>
  
  <p>===============================</p>
  
  <p>So.....something like this?</p>
  
  <pre><code>$image_string = '{R}{R}{R}{3}
  
  $Mana_symbol ='BURGWXT1-99';
  
  $output = preg_replace_all('/\{([' . $Mana_symbol. '])\}/', '&lt;img src="\1.png"/&gt;', $string);
  
  switch ($output)
  {
      case ('B'):
          $mana = '&lt;img src = "black_mana.png"/&gt;';
          break;
      case ('U'):
          $mana = '&lt;img src = "blue_mana.png"/&gt;';
          break;
      case ('G'):
          $mana = '&lt;img src = "green_mana.png"/&gt;';
          break;
      case ('R'):
          $mana = '&lt;img src = "red_mana.png"/&gt;';
          break;
      case ('W'):
          $mana = '&lt;img src = "white_mana.png"/&gt;';
          break;
      case ('1'):
          $mana = '&lt;img src = "1_colorless_mana.png"/&gt;';
          break;
      case ('2'):
          $mana = '&lt;img src = "2_colorless_mana.png"/&gt;';
          break;
      case ('3'):
          $mana = '&lt;img src = "3_colorless_mana.png"/&gt;';
          break;
  
          ....etc....
  </code></pre>
  
  <p>Should't I use preg_replace_all since there will be some with multiple instances of this? Like in the case  example as the $image_string above it will replace all occurances in the string that match?</p>