1. 程式人生 > >php獲取JSON配置檔案資料

php獲取JSON配置檔案資料

/* 獲取配置檔案url */
function getImagePath($file_url) {
    /* 從檔案中讀取資料到PHP變數  */
    $json_string = file_get_contents($file_url);
    /* 用引數true把JSON字串強制轉成PHP陣列 */
    $path = json_decode($json_string, true);
    if (!is_array($path)) die("讀取配置檔案失敗!");
    /* 列印資料 */
    //print_r($path);
    return $path["image"]["path"];
}

/* Global配置檔案 */

{
    "image": {
        "path": "D:/workspace/demo/Image/"
    },
    "other": {
        "info": "infomation"
    }
}