php - read out every char of (icon-) font -


i have (icon-)font , want read php out possible icons (chars) available in font list them. there php function or libary makes possible? doesnt matter filetype font because of them available: svg, eot, ttf, woff.

edit: on github: https://github.com/blacksunshinecoding/svgfontreader

now have found solution , built class it:

class svgfontreader {      function listglyphs($svgfile) {         $allglyphs = $this->getglyphs($svgfile);         return implode(',', $allglyphs);     }      function getglyphs($svgfile) {         $svgcopy = 'font.svg';          if (file_exists($svgcopy)) {             unlink($svgcopy);         }         copy($svgfile, $svgcopy);          $svgcontent = file_get_contents($svgcopy);          $xmlinit = simplexml_load_string($svgcontent);         $svgjson = json_encode($xmlinit);         $svgarray = json_decode($svgjson, true);          $svgglyphs = $svgarray['defs']['font']['glyph'];          if (count($svgglyphs) > 0) {              foreach ($svgglyphs $glyphid => $glyph) {                 $svgglyphs[$glyphid] = $glyph['@attributes']['unicode'];             }          }          return $svgglyphs;     }  } 

use followed:

$svg = dirname(__file__) . '/font-icons.svg'; // define font-file $svgfontreader = new svgfontreader; // initiate class $glyphsall = $svgfontreader->getglyphs($svg); // glyphs array $glyphslist = $svgfontreader->listglyphs($svg); //get glyphs comma separate 

some rules:

  • charset must unicode/utf8
  • you have include font in css
  • for relevant area have define font-family

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -