0
我下班回家解析XML 這是XML:XML解析需要幫助的PHP
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>code</key>
<string>27</string>
<key>programname</key>
<string>Anında İstek Hattı</string>
<key>programmername</key>
<string>Selma Akbaş</string>
<key>avatar</key>
<string>selma-akbas-11.jpg</string>
</dict>
<dict>
<key>code</key>
<string>16</string>
<key>programname</key>
<string>Beyaz Gece</string>
<key>programmername</key>
<string>Okan Karakoca</string>
<key>avatar</key>
<string>okan-karakoca-7.jpg</string>
</dict>
</array>
</plist>
我嘗試使用此代碼解析:
<?php
Header('charset=utf-8');
$test = simplexml_load_file('programlar.xml');
foreach ($test->array as $ar) {
foreach ($ar->dict as $dict) {
echo($dict->key);
echo "<br/>";
echo($dict->string);
echo "<br/>";
}
}
?>
解析已完成,但它會得到一些錯誤。 它只顯示每個字典的第一個關鍵字符串
有人可以修復此代碼嗎? 謝謝
xml格式不清楚,但是,請查看xml_parse_into_struct,它或多或少是一行代碼,請參閱php.net上的示例 – Teson 2011-01-09 00:24:09
您會得到什麼錯誤?我不希望任何人在沒有你幫助的情況下猜測或嘗試。 – alexn 2011-01-09 00:24:37