...

unicode entity reference convert

Phil Jackson
10-20-2009, 07:21 AM
<?php
# www.actwebdesigns.co.uk
# luke@actwebdesigns.co.uk
#
# This should help towards a better encoding option;
# echo unicodeConvert("i want pies &&&& poo but not « &amp; &igrave; &Ugrave; &&amp;nbsp;& && &");
# echo "<br />".htmlentities("i want pies &&&& poo but not « &amp; &igrave; &Ugrave; && && &");
# echo "<br />".html_entity_decode("i want pies &&&& poo but not « &amp; &igrave; &Ugrave; && && &");
#
# Would output to the browser:
#
# i want pies &&&& poo but not « & ì Ù & & && &
# i want pies &&&& poo but not « &amp; &igrave; &Ugrave; && && &
# i want pies &&&& poo but not « & � � && &&
#
# Source code would be;
#
# i want pies &amp;&amp;&amp;&amp; poo but not &laquo; &amp; &igrave; &Ugrave; &amp;&nbsp;&amp; &amp;&amp; &amp;
# <br />i want pies &amp;&amp;&amp;&amp; poo but not &Acirc;&laquo; &amp;amp; &amp;igrave; &amp;Ugrave; &amp;&amp; &amp;&amp; &amp;
# <br />i want pies &&&& poo but not « & � � && &&
#
# enjoy!

function unicodeConvert($str)
{

header('Content-Type:text/html; charset=UTF-8');
$entityRef = array("&" => "&amp;", '¢' => "&cent;", '¤' => "&curren;", '¦' => "&brvbar;", '¨' => "&uml;", 'ª' => "&ordf;", '¬' => "&not;", '®' => "&reg;", '°' => "&deg;", '²' => "²", '´' => "&acute;", '¶' => "&para;", '¸' => "&cedil;", 'º' => "&ordm;", '¼' => "¼", '¾' => "¾", 'À' => "&Agrave;", 'Â' => "&Acirc;", 'Ä' => "&Auml;", 'Æ' => "&AElig;", 'È' => "&Egrave;", 'Ê' => "&Ecirc;", 'Ì' => "&Igrave;", 'Î' => "&Icirc;", 'Ð' => "&ETH;", 'Ò' => "&Ograve;", 'Ô' => "&Ocirc;", 'Ö' => "&Ouml;", 'Ø' => "&Oslash;", 'Ú' => "&Uacute;", 'Ü' => "&Uuml;", 'Þ' => "&THORN;", 'à' => "&agrave;", 'â' => "&acirc;", 'ä' => "&auml;", 'æ' => "&aelig;", 'è' => "&egrave;", 'ê' => "&ecirc;", 'ì' => "&igrave;", 'î' => "&icirc;", 'ð' => "&eth;", 'ò' => "&ograve;", 'ô' => "&ocirc;", 'ö' => "&ouml;", 'ø' => "&oslash;", 'ú' => "&uacute;", 'ü' => "&uuml;", 'þ' => "&thorn;", '¡' => "&iexcl;", '£' => "&pound;", '¥' => "&yen;", '§' => "&sect;", '©' => "&copy;", '«' => "&laquo;", '¯' => "&macr;", '±' => "&plusmn;", '³' => "³", 'µ' => "&micro;", '·' => "&middot;", '¹' => "¹", '»' => "&raquo;", '½' => "½", '¿' => "&iquest;", 'Á' => "&Aacute;", 'Ã' => "&Atilde;", 'Å' => "&Aring;", 'Ç' => "&Ccedil;", 'É' => "&Eacute;", 'Ë' => "&Euml;", 'Í' => "&Iacute;", 'Ï' => "&Iuml;", 'Ñ' => "&Ntilde;", 'Ó' => "&Oacute;", 'Õ' => "&Otilde;", '×' => "&times;", 'Ù' => "&Ugrave;", 'Û' => "&Ucirc;", 'Ý' => "&Yacute;", 'ß' => "&szlig;", 'á' => "&aacute;", 'ã' => "&atilde;", 'å' => "&aring;", 'ç' => "&ccedil;", 'é' => "&eacute;", 'ë' => "&euml;", 'í' => "&iacute;", 'ï' => "&iuml;", 'ñ' => "&ntilde;", 'ó' => "&oacute;", 'õ' => "&otilde;", '÷' => "&divide;", 'ù' => "&ugrave;", 'û' => "&ucirc;", 'ý' => "&yacute;", 'ÿ' => "&yuml;");

foreach($entityRef as $key => $obj)
{
if($key!="&")
{
$str = str_replace($key, $obj, $str);
}
else
{
$str = preg_replace("#&((?!(quot;)|(amp;)|(cent;)|(curren;)|(brvbar;)|(uml;)|(ordf;)|(not;)|(reg;)|(deg;)|(sup2;)|(acute;)| (para;)|(cedil;)|(ordm;)|(frac14;)|(frac34;)|(Agrave;)|(Acirc;)|(Auml;)|(AElig;)|(Egrave;)|(Ecirc;)| (Igrave;)|(Icirc;)|(ETH;)|(Ograve;)|(Ocirc;)|(Ouml;)|(Oslash;)|(Uacute;)|(Uuml;)|(THORN;)|(agrave;)| (acirc;)|(auml;)|(aelig;)|(egrave;)|(ecirc;)|(igrave;)|(icirc;)|(eth;)|(ograve;)|(ocirc;)|(ouml;)|(o slash;)|(uacute;)|(uuml;)|(thorn;)|(iexcl;)|(pound;)|(yen;)|(sect;)|(copy;)|(laquo;)|(macr;)|(plusmn ;)|(sup3;)|(micro;)|(middot;)|(sup1;)|(raquo;)|(frac12;)|(iquest;)|(Aacute;)|(Atilde;)|(Aring;)|(Cce dil;)|(Eacute;)|(Euml;)|(Iacute;)|(Iuml;)|(Ntilde;)|(Oacute;)|(Otilde;)|(times;)|(Ugrave;)|(Ucirc;)| (Yacute;)|(szlig;)|(aacute;)|(atilde;)|(aring;)|(ccedil;)|(eacute;)|(euml;)|(iacute;)|(iuml;)|(ntild e;)|(oacute;)|(otilde;)|(divide;)|(ugrave;)|(ucirc;)|(yacute;)|(yuml;)|(nbsp;)|(lt;)|(gt;)))#is", $obj, $str);
}
}
return $str;
}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum