简体   繁体   中英

Why php code does not echo anything?

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

Where am i going wrong in above code??? it does not echo anything, trying on localhost

Try this:

$font = new DOMDocument();
$font->load("fonts/font.svg");
$glyphs = $font->getElementsByTagName('glyph');

foreach($glyphs as $g) {
    echo $g->getAttribute('glyph-name');
}

UPDATE:

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

UPDATE:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM