Jump to content

Parsing Mani Admin clients.txt


Loldongs

Recommended Posts

Hey guys,

 

I need to find out a way to parse this information in php so i can get the playername steamid and stuff out of this and into a variable

 

"clients.txt"
{
"version"	"1"

// This key group lists all your client players
"players"
{
	// This must be a unique client name
	"Mitchy"
	{
		// Client real name
		"name"	"mitchy"
		// Steam ID for client
		"steam"	"STEAM_0:1:13015481"
		// These are personal access flags for a player
		"flags"
		{
			"Immunity"	"grav ping a b c d e f g h i k l m n o p q r s t u v w x y"
			"Immunity"	"autojoin"
			"Admin"	"q2 q3 grav pban A B C D E F G H I J K L M N O P Q R S T U V"
			"Admin"	"W X Y Z a b c d e f g i k l m o p q r s t v w x y z client"
			"Admin"	"admin spray"
		}
	}
}
}

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/115451-parsing-mani-admin-clientstxt/
Share on other sites

<pre>
<?php
$data = <<<DATA
"clients.txt"
{
"version"	"1"

// This key group lists all your client players
"players"
{
	// This must be a unique client name
	"Mitchy"
	{
		// Client real name
		"name"	"mitchy"
		// Steam ID for client
		"steam"	"STEAM_0:1:13015481"
		// These are personal access flags for a player
		"flags"
		{
			"Immunity"	"grav ping a b c d e f g h i k l m n o p q r s t u v w x y"
			"Immunity"	"autojoin"
			"Admin"	"q2 q3 grav pban A B C D E F G H I J K L M N O P Q R S T U V"
			"Admin"	"W X Y Z a b c d e f g i k l m o p q r s t v w x y z client"
			"Admin"	"admin spray"
		}
	}
}
}
DATA;

preg_match_all('/"(name|steam)"\s+"([^"]+)"/', $data, $matches);
$count = 0;
foreach ($matches[1] as $match) {
	$result[$match] = $matches[2][$count];
	++$count;
}
print_r($result);
?>
</pre>

Thanks for that but the real problem is that i have multiple users and i need to get the flags out as well and thats being a total b***

 

example:

 

		// This must be a unique client name
	"Mitchy"
	{
		// Client real name
		"name"	"mitchy"
		// Steam ID for client
		"steam"	"STEAM_0:1:13015481"
		// These are personal access flags for a player
		"flags"
		{
			"Immunity"	"grav ping a b c d e f g h i k l m n o p q r s t u v w x y"
			"Immunity"	"autojoin"
			"Admin"	"q2 q3 grav pban A B C D E F G H I J K L M N O P Q R S T U V"
			"Admin"	"W X Y Z a b c d e f g i k l m o p q r s t v w x y z client"
			"Admin"	"admin spray"
		}
	}

	// This must be a unique client name
	"Dean"
	{
		// Client real name
		"name"	"Dean"
		// Steam ID for client
		"steam"	"STEAM_0:1:1337"
		// These are personal access flags for a player
		"flags"
		{
			"Immunity"	"grav ping a b c d e f g h i k l m n o p q r s t u v w x y"
			"Immunity"	"autojoin"
			"Admin"	"q2 q3 grav pban A B C D E F G H I J K L M N O P Q R S T U V"
			"Admin"	"W X Y Z a b c d e f g i k l m o p q r s t v w x y z client"
			"Admin"	"admin spray"
		}
	}

<pre>
<?php
$data = <<<DATA
"clients.txt"
{
"version"	"1"

// This key group lists all your client players
"players"
{
	// This must be a unique client name
	"Mitchy"
	{
		// Client real name
		"name"	"mitchy"
		// Steam ID for client
		"steam"	"STEAM_0:1:13015481"
		// These are personal access flags for a player
		"flags"
		{
			"Immunity"	"grav ping a b c d e f g h i k l m n o p q r s t u v w x y"
			"Immunity"	"autojoin"
			"Admin"	"q2 q3 grav pban A B C D E F G H I J K L M N O P Q R S T U V"
			"Admin"	"W X Y Z a b c d e f g i k l m o p q r s t v w x y z client"
			"Admin"	"admin spray"
		}
	}
}
}
DATA;

preg_match_all('/"(name|steam|flags)"\s+[\{"]((?(?<=\{)[^\}]+|[^"]+))/', $data, $matches);
$count = 0;
foreach ($matches[1] as $match) {
	$val = $matches[2][$count];
	if (substr_count($val, '"') > 4) {
		$result[$match] = array();
		$pieces = preg_split('/\s*"\s*/', $val, -1, PREG_SPLIT_NO_EMPTY);
		$piece_count = -1;
		foreach ($pieces as $piece) {
			++$piece_count;
			if ($piece_count % 2) {
				continue;
			}
			if (array_key_exists($piece, $result[$match])) {
				array_push($result[$match][$piece], $pieces[$piece_count+1]); 
			}
			else {
				$result[$match][$piece] = array($pieces[$piece_count+1]);
			}
		}
	}
	else {
		$result[$match] = $val;
	}
	++$count;
}
print_r($result);
?>
</pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.