$val) { $type = gettype($key); if ($type == "integer") { $keystr = ""; $left = "[ "; $right = " ]"; } else { $keystr = $key . ":"; } $type = gettype($val); switch($type) { case "array": $str[] = $this->compose($key, $val); break; case "integer": case "double": $str[] = $keystr . $val; break; case "string": default: if ($val) $str[] = $keystr . "\"$val\""; break; } } } return $block . ":" . $left . implode(" ",$str) . $right; } function compose_block($key, $val) { return $str; } function parse($msg) { $PREG_KEY = '([A-Za-z0-9_\-]+)'; $PREG_BLOCK_VALUE = '(\d+|\"[^\"]*\"|\{[^\}]*\}|\[[^\]]*\]|%[0-9A-Fa-f]+)'; $PREG_VALUE = '(\d+|\"[^\"]*\"|%[0-9A-Fa-f]+)'; $PREG_BLOCK = '(\{[^\}]*\}|\[[^\]]*\])'; if (preg_match_all("/$PREG_KEY:$PREG_BLOCK_VALUE/",$msg,$matches)) { for ($i=0; $iparse($val); } } } else { if (preg_match_all("/$PREG_VALUE/",$msg,$matches)) { for ($i=0; $icompose("student", array(name => "Robey", scores => array( math => "B", physics => "C"))); echo $msg; echo "
\n"; echo "
\n";
	
	var_dump($x->parse($msg));

	echo "\n
"; echo "
\n"; $msg = $x->compose("friends", array("Gilly", "Simba")); echo $msg; echo "
\n"; echo "
\n";
	
	var_dump($x->parse($msg));

	echo "\n
"; echo "
\n"; $msg = $x->compose("say", array( nick => "Robey", text => "is anybody alive in here?")); echo $msg; echo "
\n"; echo "
\n";
	
	var_dump($x->parse($msg));

	echo "\n
"; $msg = $x->compose("ping"); echo $msg; echo "
\n"; echo "
\n";
	
	var_dump($x->parse($msg));

	echo "\n
"; ?>