php获取JSON配置文件数据

版权声明:本文为博主原创作品,转载请声明出处! https://blog.csdn.net/u011086209/article/details/84966004

/* 获取配置文件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"
    }
}

猜你喜欢

转载自blog.csdn.net/u011086209/article/details/84966004
今日推荐