Ausgabe von Variablen?
Verfasst: Do 31.Jan, 2008 09:47
Hi!
Ich versuche gerade ein PHP Script (CoD Live Statistic) an das PHPBB2 Templatesystem anzupassen. Im Orginal sieht diese Statistik so aus. Dummerweise wird die HTML Ausgabe direkt in diesem Script erstellt. Also habe ich ein passendes Template geschrieben, welches ungefähr so aussehen soll. Nun hänge ich am eigentlichen PHP Code fest und bräuchte bitte mal DEN Denkanstoß um folgendes so umzuschreiben, das ich in das Template nur noch die Variablen eintragen muss. So sieht es auszugsweise aus:
Ab Zeile 131 beginnt die HTML Ausgabe. Wie müsste es z.B. aussehen, damit in Zeile 148 dies mittels Variable {HOSTMAME} im Template angezeigt wird?
So habe ich es erfolglos versucht:
Ich versuche gerade ein PHP Script (CoD Live Statistic) an das PHPBB2 Templatesystem anzupassen. Im Orginal sieht diese Statistik so aus. Dummerweise wird die HTML Ausgabe direkt in diesem Script erstellt. Also habe ich ein passendes Template geschrieben, welches ungefähr so aussehen soll. Nun hänge ich am eigentlichen PHP Code fest und bräuchte bitte mal DEN Denkanstoß um folgendes so umzuschreiben, das ich in das Template nur noch die Variablen eintragen muss. So sieht es auszugsweise aus:
Code: Alles auswählen
function farben($string) {
$string = str_replace("^0", "<font color=\"lightgray\">", $string);
$string = str_replace("^1", "<font color=\"red\">", $string);
$string = str_replace("^2", "<font color=\"green\">", $string);
$string = str_replace("^3", "<font color=\"yellow\">", $string);
$string = str_replace("^4", "<font color=\"blue\">", $string);
$string = str_replace("^5", "<font color=\"lightblue\">", $string);
$string = str_replace("^6", "<font color=\"magenta\">", $string);
$string = str_replace("^7", "<font color=\"white\">", $string);
$string = str_replace("^8", "<font color=\"lightgray\">", $string);
$string = str_replace("^9", "<font color=\"white\">", $string);
return $string . "</font>";
}
function farbig($string) {
$string = str_replace("^0", "", $string);
$string = str_replace("^1", "", $string);
$string = str_replace("^2", "", $string);
$string = str_replace("^3", "", $string);
$string = str_replace("^4", "", $string);
$string = str_replace("^5", "", $string);
$string = str_replace("^6", "", $string);
$string = str_replace("^7", "", $string);
$string = str_replace("^8", "", $string);
$string = str_replace("^9", "", $string);
return $string;
}
$server_ip = "udp://" . $server_ip;
$serverip = substr($server_ip, 6);
$connect = fsockopen($server_ip, $server_port, $errno, $errstr, 30);
if ($connect) {
socket_set_timeout ($connect, 1, 000000);
$send = "ÿÿÿÿ" . chr (0x02) . "getstatus";
$debug1 = fputs($connect, $send);
$debug2 = fwrite ($connect, $send);
$output = fread ($connect, 1);
if (! empty ($output)) {
do {
$status_pre = socket_get_status ($connect);
$output = $output . fread ($connect, 1);
$status_post = socket_get_status ($connect);
} while ($status_pre['unread_bytes'] != $status_post['unread_bytes']);
};
fclose($connect);
$output = explode ("\\", $output);
$max_index = array_search ("sv_maxclients", $output);$max_clients = $output[$max_index+1];
$max_index = array_search ("sv_privateClients", $output);$privat = $output[$max_index+1];
$max_index = array_search ("mapname", $output);$mapname = $output[$max_index+1];
$max_index = array_search ("sv_hostname", $output);$hostname = $output[$max_index+1];
$max_index = array_search ("g_gametype", $output);$gametype = $output[$max_index+1];
$max_index = array_search ("sv_punkbuster", $output);$punkbuster = $output[$max_index+1];
$max_index = array_search ("sv_pure", $output);$pure = $output[$max_index+1];
$max_index = array_search ("sv_voice", $output);$voice = $output[$max_index+1];
$max_index = array_search ("g_antilag", $output);$alag = $output[$max_index+1];
$max_index = array_search ("pswrd", $output);$passwort = $output[$max_index+1];
$max_index = array_search ("_Location", $output);$Standort = $output[$max_index+1];
$max_index = array_search ("_Admin", $output);$admin = $output[$max_index+1];
$max_index = array_search ("_Website", $output);$Web = $output[$max_index+1];
$max_index = array_search ("_Host", $output);$Host = $output[$max_index+1];
$max_index = array_search ("_Email", $output);$EMail = $output[$max_index+1];
$max_index = array_search ("_IRC", $output);$IRC = $output[$max_index+1];
$max_index = array_search ("_ICQ", $output);$ICQ = $output[$max_index+1];
$max_index = array_search ("gamename", $output);$gamename = $output[$max_index+1];
$max_index = array_search ("shortversion", $output);$Version = $output[$max_index+1];
$max_index = array_search ("_Mod", $output);$Mod = $output[$max_index+1];
$max_index = array_search ("sv_maxPing", $output);$maxPing = $output[$max_index+1];
$max_index = array_search ("sv_minPing", $output);$minPing = $output[$max_index+1];
$max_index = array_search ("fs_game", $output);$fsgame = $output[$max_index+1];
if ($Maps[$mapname] || "") {$mapnamelong = $Maps[$mapname];}
if ($mapnamelong == "") {$mapnamelong = $mapname;}
if ($fsgame == "_Admin") {$fsgame = "";}
if ($Host == "_Admin") {$Host = "";}
if ($Host == "Admin") {$Host = "";}
if ($Mod == "_Admin") {$Mod = "";}
if ($Mod == "Admin") {$Mod = "";}
if ($IRC == "_Admin") {$IRC = "";}
if ($IRC == "#") {$IRC = "-";}
if ($ICQ == "_Admin") {$ICQ = "-";}
if ($ICQ == "Admin") {$ICQ = "-";}
if ($maxPing == "_Admin") {$maxPing = "-";}
if ($Web == "_Admin") {$Web = "-";}
if ($minPing == "_Admin") {$minPing = "-";}
if ($gamename == "Call of Duty 2") {$GameIcon = "cod2";}
if ($gametype == "re") {$gametype = "Retrieval";}
if ($gametype == "dm") {$gametype = "Deathmatch";}
if ($gametype == "sd") {$gametype = "Suchen and Zerstören";}
if ($gametype == "tdm") {$gametype = "Team Deathmatch";}
if ($gametype == "bel") {$gametype = "Hinter feindl. Linien";}
if ($gametype == "hq") {$gametype = "Hauptquartier";}
if ($gametype == "dom") {$gametype = "Domination";}
if ($gametype == "ctf") {$gametype = "Capture the Flag";}
if ($gametype == "bas") {$gametype = "Base Assault";}
$last_value = count($output) - 1;
$players_string = $output[$last_value];
$players_string = explode("\n", $players_string);
for ($i = 1; $i != count($players_string); $i++) {
$split = explode(" ", $players_string[$i], 3);
$playerlist[$i-1]['score'] = $split[0];
$playerlist[$i-1]['ping'] = $split[1];
$playerlist[$i-1]['player'] = $split[2];
}
function cmp ($a, $b) {
if ($a["score"] > $b["score"]) {
return -1;
}
if ($a["score"] < $b["score"]) {
return 1;
}
if ($a["score"] == $b["score"]) {
return 0;
}
}
@usort($playerlist, "cmp");
$players = count($playerlist) - 1;
}
// Server erreichbar :
if (!$max_clients) {
?>
<table align="center" >
<tr>
<td><font size="2"><font color="#DADADA"><center><br><br> IP : <?=$serverip?> : <?=$server_port?> <br></font></font><br>
<img src="<?=$img_offline?>" border="0"><br><br><font color="#DADADA">Der Server ist OffLine <br>Es werden keine Daten vom Server empfangen.<br>Bitte überprüfen Sie die richtige Eingabe der IP-Adresse und des Serverports<br>Der Server wird in 60 Sek. neu abgefragt.</font></center></td>
</tr>
</table>
<?
exit;
}
//Ausgabe:
?>
<link rel="stylesheet" href="Style.css">
<table border="0" align="center" cellspacing="0" width="700">
<tr>
<td width="700" cellspacing="0" ><center><font size="4"><?=farben($hostname)?></font></font></center></td>
</tr>
</table>
[...]Code: Alles auswählen
<?=farben($hostname)?>So habe ich es erfolglos versucht:
Code: Alles auswählen
// Server erreichbar :
if (!$max_clients)
{
$template->assign_vars(array(
'server_port' => $_SERVER["SERVER_PORT"],
'server_software' => $_SERVER["SERVER_SOFTWARE"],
'gametype' => $gametype["GAMETYPE"],
'server_version' => $Version,
'server_hostname' => $_SERVER["SERVER_HOSTNAME"]
)
);
}