function unicodeEntities($str) {
$char = array(
'Š','’','–','š',
'"','<','>','¡','¢','£','¤','¥','¦','§',
'¨','©','ª','«','¬','','®','¯','°','±',
'²','³','´','µ','¶','·','¸','¹','º','»',
'¼','½','¾','¿','À','Á','Â','Ã','Ä','Å',
'Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï',
'Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù',
'Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã',
'ä','å','æ','ç','è','é','ê','ë','ì','í',
'î','ï','ð','ñ','ò','ó','ô','õ','ö','÷',
'ø','ù','ú','û','ü','ý','þ','ÿ');
$xmlcode = array(
'&sharp138;','&sharp146;','&sharp150;','&sharp154;',
'&sharp34;', '&sharp60;', '&sharp62;', '&sharp161;','&sharp162;','&sharp163;','&sharp164;','&sharp165;','&sharp166;','&sharp167;',
'&sharp168;','&sharp169;','&sharp170;','&sharp171;','&sharp172;','&sharp173;','&sharp174;','&sharp175;','&sharp176;','&sharp177;',
'&sharp178;','&sharp179;','&sharp180;','&sharp181;','&sharp182;','&sharp183;','&sharp184;','&sharp185;','&sharp186;','&sharp187;',
'&sharp188;','&sharp189;','&sharp190;','&sharp191;','&sharp192;','&sharp193;','&sharp194;','&sharp195;','&sharp196;','&sharp197;',
'&sharp198;','&sharp199;','&sharp200;','&sharp201;','&sharp202;','&sharp203;','&sharp204;','&sharp205;','&sharp206;','&sharp207;',
'&sharp208;','&sharp209;','&sharp210;','&sharp211;','&sharp212;','&sharp213;','&sharp214;','&sharp215;','&sharp216;','&sharp217;',
'&sharp218;','&sharp219;','&sharp220;','&sharp221;','&sharp222;','&sharp223;','&sharp224;','&sharp225;','&sharp226;','&sharp227;',
'&sharp228;','&sharp229;','&sharp230;','&sharp231;','&sharp232;','&sharp233;','&sharp234;','&sharp235;','&sharp236;','&sharp237;',
'&sharp238;','&sharp239;','&sharp240;','&sharp241;','&sharp242;','&sharp243;','&sharp244;','&sharp245;','&sharp246;','&sharp247;',
'&sharp248;','&sharp249;','&sharp250;','&sharp251;','&sharp252;','&sharp253;','&sharp254;','&sharp255;');
$str = str_replace($char, $xmlcode, $str);
return $str;
}
// run this first
function xmlEntities($str) {
$char = array("&");
$xslt = array('&sharp38;');
$str = str_replace($char, $xslt, $str);
$htmlchar = array(
'&Scaron;','&rsquo;','&ndash;','&scaron;',
'&quot;','&amp;','&lt;','&gt;','&nbsp;','&iexcl;','&cent;','&pound;','&curren;','&yen;',
'&brvbar;','&sect;','&uml;','&copy;','&ordf;','&laquo;','&not;','&shy;','&reg;','&macr;',
'&deg;','&plusmn;','&sup2;','&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;',
'&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&Agrave;','&Aacute;','&Acirc;','&Atilde;',
'&Auml;','&Aring;','&AElig;','&Ccedil;','&Egrave;','&Eacute;','&Ecirc;','&Euml;','&Igrave;','&Iacute;',
'&Icirc;','&Iuml;','&ETH;','&Ntilde;','&Ograve;','&Oacute;','&Ocirc;','&Otilde;','&Ouml;','&times;',
'&Oslash;','&Ugrave;','&Uacute;','&Ucirc;','&Uuml;','&Yacute;','&THORN;','&szlig;','&agrave;','&aacute;',
'&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;',
'&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;',
'&ouml;','&divide;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;');
$xmlcode = array(
'&sharp138;','&sharp146;','&sharp150;','&sharp154;',
'&sharp34;', '&sharp38;', '&sharp60;', '&sharp62;', '&sharp160;','&sharp161;','&sharp162;','&sharp163;','&sharp164;','&sharp165;',
'&sharp166;','&sharp167;','&sharp168;','&sharp169;','&sharp170;','&sharp171;','&sharp172;','&sharp173;','&sharp174;','&sharp175;',
'&sharp176;','&sharp177;','&sharp178;','&sharp179;','&sharp180;','&sharp181;','&sharp182;','&sharp183;','&sharp184;','&sharp185;',
'&sharp186;','&sharp187;','&sharp188;','&sharp189;','&sharp190;','&sharp191;','&sharp192;','&sharp193;','&sharp194;','&sharp195;',
'&sharp196;','&sharp197;','&sharp198;','&sharp199;','&sharp200;','&sharp201;','&sharp202;','&sharp203;','&sharp204;','&sharp205;',
'&sharp206;','&sharp207;','&sharp208;','&sharp209;','&sharp210;','&sharp211;','&sharp212;','&sharp213;','&sharp214;','&sharp215;',
'&sharp216;','&sharp217;','&sharp218;','&sharp219;','&sharp220;','&sharp221;','&sharp222;','&sharp223;','&sharp224;','&sharp225;',
'&sharp226;','&sharp227;','&sharp228;','&sharp229;','&sharp230;','&sharp231;','&sharp232;','&sharp233;','&sharp234;','&sharp235;',
'&sharp236;','&sharp237;','&sharp238;','&sharp239;','&sharp240;','&sharp241;','&sharp242;','&sharp243;','&sharp244;','&sharp245;',
'&sharp246;','&sharp247;','&sharp248;','&sharp249;','&sharp250;','&sharp251;','&sharp252;','&sharp253;','&sharp254;','&sharp255;');
$str = str_replace($htmlchar, $xmlcode, $str);
// $str = str_ireplace($htmlchar, $xmlcode, $str);
return $str;
}
To use, replace “sharp” to “#”.
You can add more characters as you need. Reference link: http://www.alanwood.net/demos/ansi.html