View Single Post
Old 10-14-2009, 09:47 AM   #1 (permalink)
cachepl0x
That guy
 
cachepl0x's Avatar
 
Join Date: Sep 2009
Location: San Antonio, TX
Posts: 24
Thanks: 0
cachepl0x is on a distinguished road
Default Simple, bored, probably useless.

Well, I haven't had any sleep (woot 26 hours), and I found that PHP's json decode was not simple, nor clean enough for my taste, so I made an incredibly simple, probably useless function for it.

PHP Code:
function jsonParse ($file$col) {
    
$json file_get_contents($file);
    
$obj  json_decode($json);
    return 
$obj->{$col};

And you would use it like this:

PHP Code:
jsonParse ('settings.json''name'); 
Assuming you have a file called "settings.json," and let's just get an example for it:

Code:
{
    "host" : "localhost",
    "user" : "marc",
    "pass" : "lolmypass",
    "name" : "database name"
}

Last edited by cachepl0x : 10-14-2009 at 09:57 AM. Reason: Changed double quotes to single quotes
cachepl0x is offline  
Reply With Quote