TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Tips & Tricks (http://www.talkphp.com/tips-tricks/)
-   -   Simple, bored, probably useless. (http://www.talkphp.com/tips-tricks/5025-simple-bored-probably-useless.html)

cachepl0x 10-14-2009 09:47 AM

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"
}



All times are GMT. The time now is 03:31 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0