是否可以使用PHP輸出特定的JSON數據(從Firefox書籤導出)。輸出Firefox JSON數據
這是我到目前爲止的代碼,它將重新編碼數據,因爲Firefox不會以正確的UTF-8方式導出它。我也從文件末尾刪除尾部。
<?php
// Read the file blah blah
$hFile = "../uploads/james.json";
$hFile = file_get_contents($hFile);
$hFile = utf8_encode($hFile);
// Remove the trailing comma because Firefox is lazy!!!!
$hFile = substr($hFile, 0, strlen($hFile)-3) . "]}";
$hDec = json_decode(fixEncoding($hFile));
foreach($hDec['uri'] as $hURI) {
// Output here
}
// Fixes the encoding to UTF-8
function fixEncoding($in_str) {
$cur_encoding = mb_detect_encoding($in_str);
if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")){
return $in_str;
}else{
return utf8_encode($in_str);
}
}
?>
我一直無法得到任何輸出除了整個數據,使用var_dump。
那麼這有可能嗎? – 2009-05-24 20:52:45
我試圖避免使用庫,但如果這確實結束是唯一的選擇,我會研究它。 – 2009-05-24 22:15:46