Firefoxのブックマークのバックアップのjson

ブックマークのバックアップはjsonの形式で出力されている。phpで取り出してみる。childrenで階層になっているので、それも全部抜き出している。7階層まで取り出し、そこまで内包してなかった。

<?php
$json=file_get_contents("bookmarks.json");
$obj = json_decode($json,false,512,JSON_BIGINT_AS_STRING);
echo  $obj->guid.",\"".$obj->title."\",".$obj->dateAdded.",".$obj->type.",".$obj->uri."\n";
if (array_key_exists('children',$obj)){
  foreach($obj->children as $key){
    echo $key->guid.",\"".$key->title."\",".$key->dateAdded.",".$key->type.",".$key->uri."\n";
    if (array_key_exists('children',$key)) {
      foreach($key->children as $key2){
        echo $key2->guid.",\"".$key2->title."\",".$key2->dateAdded.",".$key2->type.",".$key2->uri."\n";
        if (array_key_exists('children',$key2)) {
          foreach($key2->children as $key3){
            echo $key3->guid.",\"".$key3->title."\",".$key3->dateAdded.",".$key3->type.",".$key3->uri."\n";
            if (array_key_exists('children',$key3)) {
              foreach($key3->children as $key4){
                echo $key4->guid.",\"".$key4->title."\",".$key4->dateAdded.",".$key4->type.",".$key4->uri."\n";
                if (array_key_exists('children',$key4)) {
                  foreach($key4->children as $key5){
                    echo $key5->guid.",\"".$key5->title."\",".$key5->dateAdded.",".$key5->type.",".$key5->uri."\n";
                    if (array_key_exists('children',$key5)) {
                      foreach($key5->children as $key6){
                        echo $key6->guid.",\"".$key6->title."\",".$key6->dateAdded.",".$key6->type.",".$key6->uri."\n";
                        if (array_key_exists('children',$key6)) {
                          foreach($key6->children as $key7){
                            echo $key7->guid.",\"".$key7->title."\",".$key7->dateAdded.",".$key7->type.",".$key7->uri."\n";
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

?>

コメントを残す

作者にコメントします。

掲載には承認判定があります。