Question

I am attempting to retrieve the unicode values of glyphs in an icon font. The font is structured like this:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<font id="symbols" horiz-adv-x="1024">
<font-face units-per-em="1024" ascent="960" descent="-64" />
<missing-glyph horiz-adv-x="1024" />
<glyph unicode="&#x20;" d="" horiz-adv-x="512" />
<glyph unicode="&#xe600;" d="M1004.5 404.5q-19.5-19.5-47-19.5t-46.5 19l-15 15v-419q0-26-18.5-45t-45.5-19h-192v288q0 13-9.5 22.5t-22.5 9.5h-192q-13 0-22.5-9.5t-9.5-22.5v-288h-192q-27 0-45.5 19t-18.5 45v419l-15-15q-19-19-46.5-19t-47 19.5-19.5 47 19 46.5l444 444q20 20 49 19 29 1 49-19l444-444q19-19 19-46.5t-19.5-47z" />
<glyph unicode="&#xe601;" d="M960 576h-384v-64h258q34-1 43-10l137-94q10-10 10-24t-10-24l-137-94q-10-10-45-10h-256v-256q0-26-18.5-45t-45.5-19-45.5 19-18.5 45v256h-384q-26 0-45 19t-19 45v128q0 26 19 45t45 19h384v64h-256q-35 0-45 10l-137 94q-10 10-10 24t10 24l137 94q9 10 43 10h258v64q0 26 18.5 45t45.5 19 45.5-19 18.5-45v-64h384q26 0 45-18.5t19-45.5v-128q0-27-19-45.5t-45-18.5z" />
</font>
</defs>
</svg>

I am attempting to get the attribute unicode using DOMDocument.

if(file_exists($this->symbols)) {
    $font = new DOMDocument();
    $font->load($this->symbols);
    $glyphs = $font->getElementsByTagName('glyph');

    foreach($glyphs as $g) {
        echo $g->getAttribute('unicode');
    }
}

However, I always just get a bunch of  echo'ed out instead of the actual unicode value. I need to use this unicode value to both display the character within the font family and to store verbatim in a database.

Was it helpful?

Solution

What you're getting is the right answer. That's the UTF-8 hex value for the attribute. What you seem to expect is the UTF16 value but it's just the same thing expressed in a different way.

iconv can be used to convert between UTF-8 and UTF-16 so if you iconv the result and then pass that into bin2hex you should be able to get the UTF-16 value as a string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top