<?php
$svg_file = file_get_contents("fonts/font.svg");
$font = new DOMDocument();
$font->load($svg_file);
$glyphs = $font->getElementsByTagName('glyph');
foreach($glyphs as $g) {
echo $g->getAttribute('glyph-name');
}
?>
上面的代码在哪里出错?它没有回应任何东西,试试localhost
答案 0 :(得分:0)
试试这个:
$font = new DOMDocument();
$font->load("fonts/font.svg");
$glyphs = $font->getElementsByTagName('glyph');
foreach($glyphs as $g) {
echo $g->getAttribute('glyph-name');
}
<强>更新强>
$font = new DOMDocument();
$font->load("fonts/font.svg");
$glyphs = $font->getElementsByTagName('glyph');
$arr_names = array();
foreach($glyphs as $g) {
$arr_names[] = $g->nodeValue;
}
$sort($arr_names);
foreach($arr_names as $name){
echo $name;
}
<强>更新强>
$font = new DOMDocument();
$font->load("fonts/font.svg");
$glyphs = $font->getElementsByTagName('glyph');
$arr_names = array();
foreach($glyphs as $g) {
$arr_names[] = $g->nodeValue;
}
sort($arr_names);
foreach($arr_names as $name){
echo $name;
}