360 瀏覽器匯出的書籤資料庫(`favdb`)實為 SQLite 格式,本文提供 PHP 腳本將其解析並轉換為標準 Netscape 書籤 HTML 格式(`bookmark.html`),方便匯入其他瀏覽器。
<?php
$bookmark_file = 'book_mark.html';
$json_file = 'tb_fav.json';
// 1. 讀取並解碼 JSON
$content = file_get_contents($json_file);
if ($content === false) {
die("無法讀取 $json_file");
}
$data = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
die("JSON 解析失敗: " . json_last_error_msg());
}
$records = $data['RECORDS'] ?? [];
// 2. 輸出 HTML 標頭
$header = "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n"
. "<!-- This is an automatically generated file. It will be read and overwritten. Do Not Edit! -->\n"
. "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n"
. "<TITLE>Bookmarks</TITLE>\n"
. "<H1>Bookmarks</H1>\n"
. "<DL><p>\n";
file_put_contents($bookmark_file, $header);
// 3. 逐筆寫入書籤項目
foreach ($records as $item) {
$href = htmlspecialchars($item['url'] ?? '', ENT_QUOTES, 'UTF-8');
$add_date = $item['create_time'] ?? time();
$last_visit = $item['last_modify_time'] ?? time();
$last_mod = $last_visit + 1;
$title = htmlspecialchars($item['title'] ?? 'Untitled', ENT_QUOTES, 'UTF-8');
$line = "<DT><A HREF=\"$href\" ADD_DATE=\"$add_date\" LAST_VISIT=\"$last_visit\" LAST_MODIFIED=\"$last_mod\">$title</A><br/>\n";
file_put_contents($bookmark_file, $line, FILE_APPEND);
}
// 4. 輸出結尾
$tail = "</DL><p>\n";
file_put_contents($bookmark_file, $tail, FILE_APPEND);
echo "成功產生 $bookmark_file";
?>
執行腳本後產生的 `book_mark.html` 可直接在 Chrome、Firefox、Edge 等瀏覽器匯入書籤功能中使用。