...

View Full Version : Resolved char encode function



Phil Jackson
10-19-2009, 11:10 PM
hi all just wrote this:



<?php

function unicodeConvert($str)
{
header('Content-Type:text/html; charset=UTF-8');
$entityRef = array('"' => "&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;", '' => "&oslash;", '' => "&uacute;", '' => "&uuml;", '' => "&thorn;", '' => "&iexcl;", '' => "&pound;", '' => "&yen;", '' => "&sect;", '' => "&copy;", '' => "&laquo;", '' => "&macr;", '' => "&plusmn;", '' => "&sup3;", '' => "&micro;", '' => "&middot;", '' => "&sup1;", '' => "&raquo;", '' => "&frac12;", '' => "&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("#&((?!(amp;)|(igrave;)|(laquo;)|(Ugrave;)))#is", " ".$obj." ", $str);
}
}
return $str;
}

echo unicodeConvert("i want pies &&&& poo but not &amp; &igrave; &Ugrave; && && &");

?>


viewSource:
i want pies &amp; &amp; &amp; &amp; poo but not &laquo; &amp; &igrave; &Ugrave; &amp; &amp; &amp; &amp; &amp;
output to browser:

i want pies & & & & poo but not & & & & & &

problem being, it adds a space on the end of some &amp. can anyone see why?

Phil Jackson
10-19-2009, 11:41 PM
im too tiered sorted it now



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum