Removing characters(XY) inside tag only

<?php
[B]$myText[/B]='<table>
  <tr>
    <td[COLOR="#FF0000"][B]XY[/B][/COLOR]style="color:red">text1[COLOR="#FF0000"]XY[/COLOR]in[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#FF0000"]XY[/COLOR]td[COLOR="#FF0000"]XY[/COLOR]of[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#ff0000"]XY[/COLOR]tr</td>
    <td[COLOR="#FF0000"][B]XY[/B][/COLOR]class="myClass">text2[COLOR="#FF0000"]XY[/COLOR]in[COLOR="#FF0000"]XY[/COLOR]2nd[COLOR="#FF0000"]XY[/COLOR]td[COLOR="#FF0000"]XY[/COLOR]of[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#FF0000"]XY[/COLOR]tr</td>
  </tr>
  <tr>
    <td[COLOR="#FF0000"][B]XY[/B][/COLOR]colspan="2"[COLOR="#FF0000"][B]XY[/B][/COLOR]class="myClass">text3[COLOR="#FF0000"]XY[/COLOR]in[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#FF0000"]XY[/COLOR]td[COLOR="#FF0000"]XY[/COLOR]of[COLOR="#FF0000"]XY[/COLOR]2nd[COLOR="#FF0000"]XY[/COLOR]tr</td>
  </tr>
</table>'; 

I have a variable $myText like the above.
I like to remove 4 XYs which is inside between the open tag “<” and the close tag “>” without any touch of outside between the open tag “<” and the close tag “>”.

My target variable is like the following.

<?php
[B]$myTargetText[/B]='<table>
  <tr>
    <td style="color:red">text1[COLOR="#FF0000"]XY[/COLOR]in[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#FF0000"]XY[/COLOR]td[COLOR="#FF0000"]XY[/COLOR]of[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#ff0000"]XY[/COLOR]tr</td>
    <td class="myClass">text2[COLOR="#FF0000"]XY[/COLOR]in[COLOR="#FF0000"]XY[/COLOR]2nd[COLOR="#FF0000"]XY[/COLOR]td[COLOR="#FF0000"]XY[/COLOR]of[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#FF0000"]XY[/COLOR]tr</td>
  </tr>
  <tr>
    <td colspan="2" class="myClass">text3[COLOR="#FF0000"]XY[/COLOR]in[COLOR="#FF0000"]XY[/COLOR]1st[COLOR="#FF0000"]XY[/COLOR]td[COLOR="#FF0000"]XY[/COLOR]of[COLOR="#FF0000"]XY[/COLOR]2nd[COLOR="#FF0000"]XY[/COLOR]tr</td>
  </tr>
</table>'; 

How can I get $myTargetText from $myText?

What is the code that sets the value to $myText ?

It might be easier to edit that code so that your XY characters are not inserted where you don’t want them in the first place.

The following is the code that sets the value to $myText.

$myText=str_replace(' ', 'XY ', $myText);

I like to put   instead of space.
XY here menas   .

Then this now looks like the same question you posted in your other thread.

Why the cross-post?

I thought I need to make it simplify the question for the answer posters. The former question is about putting special characters into both inside and outside tags and removing the special characters inside tags.

This question is about the removig the special characters inside tags only.

As you ask “What is the code that sets the value to $myText ?”. It becomes the same question.
I admit it has essentially the same point.