2016-09-18 64 views
-1
<?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'); 
} 
?> 

我在哪裏錯了上面的代碼?它不會回任何東西,試圖在本地主機上爲什麼php代碼不會迴應任何內容?

+2

開始用'的var_dump($字形)' –

+0

我絕對是新人這個,請你詳細說明一下嗎?提前致謝。 – San

+1

將'var_dump($ glyphs)'放在'$ glyphs'賦值之後。它會詳細顯示變量的內容。任何PHP教程都應該解釋'var_dump'的用途。 – Barmar

回答

0

試試這個:

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

而我如何獲得數組的價值和回聲 – San

+0

嘗試$ g-> nodeValue – stweb

+0

上面得到解決我的要求,它迴響所有的字形名稱。我想使用所有字形名稱作爲數組來回顯每個名稱和計數名稱並對它們進行排序 – San

相關問題