为什么php代码不回应任何东西?

时间:2016-09-18 08:14:51

标签: php svg

<?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

1 个答案:

答案 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;
}