为什么php代码不回显任何内容?

为什么php代码不回显任何内容?,php,svg,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->getAttribut

我在上面的代码中哪里出错了???它不回显任何内容,在本地主机上尝试

<?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');
}
?>
更新:

$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');

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

var\u dump($glyphs)
开始,我是个新手,你能详细说明一下吗?提前感谢。将
var\u dump($glyphs)
放在
$glyphs
分配之后。它将向您详细显示变量的内容。任何PHP教程都应该解释
var\u dump
的用途。我如何获得数组和echoTry$g->nodeValueAbove的值解决了我的要求,它回显了所有glyph名称。我想使用所有的字形名称作为数组来回显每个名称和计数名称,并对它们进行排序。您需要在循环$arr_names=array()之前定义数组;并将值放入循环内的数组$arr_names[]=$g->nodeValueI我正在尝试,但我不知道我在做什么,我想我需要学习。如果你能分享完整的代码,我将不胜感激。