title: Change Text Colour of Part of a string in OpenTBS
body: <p>I'm building a large word document, and need to change the text colour of 'part' of a string, only. </p>
  
  <p>I've found similar questions in a few places <a href="https://stackoverflow.com/questions/18754590/inserting-a-bullet-point-and-styling-to-onshow-entires-in-opentbs">here</a>, <a href="https://stackoverflow.com/questions/18902268/opentbs-how-to-dynamically-change-color-of-rows-in-a-table">here</a> and <a href="http://www.tinybutstrong.com/forum.php?thr=2791" rel="nofollow noreferrer">here</a>, but where my problem seems to differ, is that I only wish to colour part of a string, as opposed to a whole paragraph, or an entire OpenTBS field, as in these examples. </p>
  
  <p>I first tried wrapping the individual chunk of string in docx XML tags, but found php converted then to entities (<code>&amp;gt;</code> etc) which clearly was no use. Currently, I've moved on to wrapping the part of the text in XML tags through a template script, which gives me a malformed XML output, I presume because I have content between the <code>&lt;/w:r&gt;</code> from one substring, and the <code>&lt;w:r&gt;</code> of the next substring.</p>
  
  <p>Any advice on how to do this properly? Below is the current code and output.</p>
  
  <pre><code>//Function called onmerge. I wrap the portion of string I want to change the text 
  //colour of with [UNTRANSLATED] and [ENDUNTRANSLATED] manually earlier, and attempt 
  //to swap them for tags at this point.
  function lb($FieldName, &amp;$CurrVal) { 
      $CurrVal= str_replace('[UNTRANSLATED]', '&lt;w:r&gt;&lt;w:rPr&gt;&lt;w:color w:val="FF0000"/&gt;&lt;/w:rPr&gt;&lt;w:t&gt;', $CurrVal); 
      $CurrVal= str_replace('[ENDUNTRANSLATED]', '&lt;/w:t&gt;&lt;/w:r&gt;', $CurrVal); 
  }
  </code></pre>
  
  <p>And the output...</p>
  
  <pre><code>&lt;w:t&gt; 
      &lt;w:r&gt; 
          &lt;w:rPr&gt; 
              &lt;w:color w:val="FF0000" /&gt; 
          &lt;/w:rPr&gt; 
          &lt;w:t&gt;Slaked Lime&lt;/w:t&gt; 
      &lt;/w:r&gt;,
      &lt;w:r&gt;
           &lt;w:rPr&gt;
               &lt;w:color w:val="FF0000" /&gt;
           &lt;/w:rPr&gt;
           &lt;w:t&gt;Air slaked Lime&lt;/w:t&gt;
      &lt;/w:r&gt;,
  [code continues in same style...]
  </code></pre>
  
  <p>Word flags the error at the point where my second block, and second <code>&lt;w:r&gt;</code> tag are. Unfortunately the error is beautifully non-descript.</p>
  
  <hr>