Sunday, November 06, 2011

IRC - Get the user list of a channel in JSON with Denora/PHPDenora

You need to have Denora and PHPDenora installed and running on your IRCd for this to work.

define("_VALID_PARENT", 1);
require ("libs/phpdenora/init.php");  //You have to provide the proper path to the file here
$link = sql_db_connect();
echo json_encode(denora_who_in_channel(mysql_real_escape_string(trim($_GET["channel"], '"'))));

It works like this :

In PHP, to get the file content and parse it into an array, you will need to do something like this :
$userlist = json_decode(file_get_contents(""), true);

To loop through the array, you will need to follow this logic :
foreach ($userlist as $userinfo) {
       foreach ($userinfo as $infokey => $infovalue) {
                //echo $infokey . " : " . $infovalue . ", ";
       //echo "\n";

If you want to access only a single attribute per user, like for example, if you only want to list the nicknames, you can access the attribute directly by its name by doing something like this :
foreach ($userlist as $userinfo) {
       echo $userinfo["nick"];

See also :

No comments:

Post a Comment