是否可以使用 PHP 输出特定的 JSON 数据(从 Firefox 书签中导出)。
这是我到目前为止的代码,它将重新编码数据,因为 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,除了整个数据之外,我无法获得任何输出。