I am trying to get superscript working in php. I am replacing the tag  with a superscript digit as shown below in the script. The output I get is O² instead of getting O². How do I fix this issue?
<?php 
$a = "O<sup>2</sup>";
$a = str_replace("<sup>2</sup>", "²", $a);
...
...
?>
I am adding the value of $a manually in the script here but I am receiving the value as a POST $_SERVER["REQUEST_METHOD"] == "POST" from external application. Basically:
    $a = htmlspecialchars_decode($POST['myValue'], ENT_QUOTES);
    $a = utf8_decode($a);
    $a = str_replace("<sup>2</sup>", "²", $a);
I even tried adding php header('Content-type: text/plain; charset=utf-8'); in the header of the php script but still no luck.
 
    