雖然後來沒這麼做, 但還是把這段檢查紀錄一下
mb_detect_encoding
$cmd = "/usr/bin/mediainfo -f $filePath --Output=XML";
exec($cmd, $output, $retval);
if ($retval===0) {
# xml to array
$xml = '';
foreach ($output as $item) {
if ('ASCII' != ($encode = mb_detect_encoding($item))) {
# 檢查若有 parser 出來的 xml 內容不為 ascii 編碼則跳過, 否則 simplexml_load_string 會有 error
# 試過用 mb_convert_encoding 與 iconv 轉編碼, 但都失敗, 所以就去除編碼有錯的部份
} else {
$xml.= $item;
}
}
$xmlObj = simplexml_load_string($xml);
$json = json_encode($xmlObj);
$ary = json_decode($json, true);
.
.
.
}
cf : http://blog.xuite.net/coke750101/networkprogramming/35093585
沒有留言:
張貼留言