Skip to content

Commit

Permalink
Deal with character/html/xml encodings slightly better.
Browse files Browse the repository at this point in the history
Fixes accounts with Warhammer 40k titles, which have all the silly "TM"
 and "(R)" unicode chars.
  • Loading branch information
icculus committed Jul 5, 2010
1 parent 08e734f commit 2cfbd1e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions steamprofile.php
Expand Up @@ -3,6 +3,19 @@

require_once('steamtags.php');

// !!! FIXME: there has got to be a better way to do this. Maybe move to
// !!! FIXME: the formal XML writer classes.
$xmlents = array('"','&','&','<','>',' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ');
$htmlents = array('"','&','&','<','>',' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ');
function xml_entities($str)
{
global $xmlents, $htmlents;
$str = htmlspecialchars($str, ENT_NOQUOTES, 'UTF-8');
$str = str_replace($htmlents, $xmlents, $str);
$str = str_ireplace($htmlents, $xmlents, $str);
return $str;
} // xml_entities

// This only dumps scalar items, because we usually want to tweak the
// child array output.
function dump_array_as_xml($name, $a)
Expand All @@ -14,7 +27,7 @@ function dump_array_as_xml($name, $a)
{
if (is_array($v))
continue; // we'll do these later.
$txt = htmlentities((string) $v);
$txt = xml_entities((string) $v);
print("<$k>$txt</$k>");
} // foreach

Expand Down Expand Up @@ -61,7 +74,7 @@ function dump_array_as_xml($name, $a)
print("<tags>");
foreach ($g['tags'] as $t)
{
$tag = htmlentities($t);
$tag = xml_entities($t);
print("<tag>$tag</tag>");
} // foreach
print("</tags>");
Expand Down

0 comments on commit 2cfbd1e

Please sign in to comment.