- json_decode: documentation ( source)
<?php
# read config file data from the file using file_get_contents
$string = '{
"mysql": {
"host": "locahost",
"port": 3306,
"database": "test",
"username": "root",
"password": ""
}
}';
$cfg = json_decode($string,1); # decode the result as an array
$host = $cfg["mysql"]["host"];
$port = $cfg["mysql"]["port"];
$database = $cfg["mysql"]["database"];
$username = $cfg["mysql"]["username"];
$password = $cfg["mysql"]["password"];
echo "host = $host, port = $port, database=$database, username=$username, password=$password";
?>