0

I've written a font generator web app in PHP which uses FontCustom to generate font files from SVG. There is an option to have fixed UTF-8 glyph codes for each svg, but i need to store this in database and need to automatize this process. FontCustom uses the PUA (Private Use Area) of UTF-8. I need to incrementally generate a valid glyph code in this area.

Example JSON from FontCustom:

[
    {
        "file": "home.svg",
        "code": "0x2302" // I need this
    },
    {
        "file": "briefcase.svg",
        "code": "0x1F001" // And this to be generated with PHP
    }
]
wintercounter
  • 7,500
  • 6
  • 32
  • 46
  • `sprintf('0x%04x', $i)`, where `$i` is a simple integer. Does that help? If not, please clarify what exactly your problem is in generating this number. – deceze Sep 16 '14 at 11:25
  • Yep, that was it! Please post as an answer and i accept it. Thanks! – wintercounter Sep 16 '14 at 11:33

1 Answers1

2

You simply want to format a regular integer in hexadecimal format. That's as simple as:

sprintf('0x%04x', $i)
deceze
  • 510,633
  • 85
  • 743
  • 889