Encoding special characters in XML for Flash with PHP

I have an xml file with special characters like single/doubkle quotes, mdashes, ellipses. I need to get these characters converted into number codes like [COLOR=RoyalBlue]“ (left double quote)[/COLOR] for flash to read.

Which PHP function do I use to convert?

<?php

header('Content-Type: text/xml');

$f = $_GET['f'];
$xmlFile = $f.".xml";

$fh = fopen($xmlFile, 'r') or die("Can't open file");
$theXML = fread($fh, filesize($xmlFile));

fclose($fh);

echo htmlspecialchars($theXML, ENT_QUOTES); //THIS IS WHERE I NEED IT TO WORK!!

?>