hi all just wrote this:
<?php
function unicodeConvert($str)
{
header('Content-Type:text/html; charset=UTF-8');
$entityRef = array('"' => """, "&" => "&", '¢' => "¢", '¤' => "¤", '¦' => "¦", '¨' => "¨", 'ª' => "ª", '¬' => "¬", '®' => "®", '°' => "°", '²' => "²", '´' => "´", '¶' => "¶", '¸' => "¸", 'º' => "º", '¼' => "¼", '¾' => "¾", 'À' => "À", 'Â' => "Â", 'Ä' => "Ä", 'Æ' => "Æ", 'È' => "È", 'Ê' => "Ê", 'Ì' => "Ì", 'Î' => "Î", 'Ð' => "Ð", 'Ò' => "Ò", 'Ô' => "Ô", 'Ö' => "Ö", 'Ø' => "Ø", 'Ú' => "Ú", 'Ü' => "Ü", 'Þ' => "Þ", 'à' => "à", 'â' => "â", 'ä' => "ä", 'æ' => "æ", 'è' => "è", 'ê' => "ê", 'ì' => "ì", 'î' => "î", 'ð' => "ð", 'ò' => "ò", 'ô' => "ô", 'ö' => "ö", 'ø' => "ø", 'ú' => "ú", 'ü' => "ü", 'þ' => "þ", '¡' => "¡", '£' => "£", '¥' => "¥", '§' => "§", '©' => "©", '«' => "«", '¯' => "¯", '±' => "±", '³' => "³", 'µ' => "µ", '·' => "·", '¹' => "¹", '»' => "»", '½' => "½", '¿' => "¿", 'Á' => "Á", 'Ã' => "Ã", 'Å' => "Å", 'Ç' => "Ç", 'É' => "É", 'Ë' => "Ë", 'Í' => "Í", 'Ï' => "Ï", 'Ñ' => "Ñ", 'Ó' => "Ó", 'Õ' => "Õ", '×' => "×", 'Ù' => "Ù", 'Û' => "Û", 'Ý' => "Ý", 'ß' => "ß", 'á' => "á", 'ã' => "ã", 'å' => "å", 'ç' => "ç", 'é' => "é", 'ë' => "ë", 'í' => "í", 'ï' => "ï", 'ñ' => "ñ", 'ó' => "ó", 'õ' => "õ", '÷' => "÷", 'ù' => "ù", 'û' => "û", 'ý' => "ý", 'ÿ' => "ÿ");
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 « & ì Ù && && &");
?>
viewSource:
i want pies & & & & poo but not « & ì Ù & & & & &
output to browser:
i want pies & & & & poo but not « & ì Ù & & & & &
problem being, it adds a space on the end of some &. can anyone see why?