...

View Full Version : Replacing text with an image



BlinkyBIll01
09-15-2011, 01:04 PM
Hey there,

I'm sure this has an easy solution but all of the searches I've done on "replacing text with image in php" has given coding that gives me an error.

This is the partial source for a "server status" page that someone was kind enough to give to me:


date_default_timezone_set('America/New_York');
function check_server_tcp($port, $site)
{
$fp = @fsockopen($site, $port, $errno, $errstr, 1);
$write = @fwrite($fp, "\x00");
if (!$write) {
return "<b><font color=\"red\">Down</font></b>";
} else {
return "<b><font color=\"green\">Up</font></b>";
fclose($fp);
}
}

function check_server($portNumber, $ip)
{
$handle = @fsockopen("udp://" . $ip, $portNumber, &$errno, &$errstr, 0);
@socket_set_timeout($handle, "1");
$write = @fwrite($handle, "\x00");
if (!$write) {
next;
}
$startTime = time();
$header = @fread($handle, 1);
$endTime = time();
$timeDiff = $endTime - $startTime;
if ($timeDiff >= "1") {
@fclose($handle);
return "<b><font color=\"green\">Up</font></b>";
} else {
@fclose($handle);
return "<b><font color=\"red\">Down</font></b>";
}
}

$login = check_server_tcp("0", "0.0.0.0");
$victory = check_server("0", "0.0.0.0");
$zukunft = check_server("0", "0.0.0.0");
$triumph = check_server("0", "0.0.0.0");
$vigilance = check_server("0", "0.0.0.0");
$champion = check_server("0", "0.0.0.0");
$pinnacle = check_server("0", "0.0.0.0");
$protector = check_server("0", "0.0.0.0");
$guardian = check_server("0", "0.0.0.0");
$liberty = check_server("0", "0.0.0.0");
$justice = check_server("0", "0.0.0.0");
$defiant = check_server("0", "0.0.0.0");
$infinity = check_server("0", "0.0.0.0");
$union = check_server("0", "0.0.0.0");
$freedom = check_server("0", "0.0.0.0");
$virtue = check_server("0", "0.0.0.0");

$test_login = check_server_tcp("0", "0.0.0.0");
$test_server = check_server("0", "0.0.0.0");

$beta_login = check_server_tcp("0", "0.0.0.0");
$beta_server = check_server("0", "0.0.0.0");

$string = "
<head>
<title>
Server Status
</title>

</head>
<body bgcolor=\"#212121\" text=\"#ffffff\">
<table>
<tr>
<td>Champion</td><td></td><td></td><td></td><td></td><td>$champion<td>
</tr>
<tr>
<td>Defiant (UK)</td><td></td><td></td><td></td><td></td><td>$defiant<td>
</tr>
<tr>
<td>Exalted (VIP)</td><td></td><td></td><td></td><td></td><td><font color='#EAC117'>Unknown</font><td>
</tr>
<tr>
<td>Freedom</td><td></td><td></td><td></td><td></td><td>$freedom<td>
</tr>
<tr>
<td>Guardian</td><td></td><td></td><td></td><td></td><td>$guardian<td>
</tr>
<tr>
<td>Infinity</td><td></td><td></td><td></td><td></td><td>$infinity<td>
</tr>
<tr>
<td>Justice</td><td></td><td></td><td></td><td></td><td>$justice<td>
</tr>
<tr>
<td>Liberty</td><td></td><td></td><td></td><td></td><td>$liberty<td>
</tr>
<tr>
<td>Pinnacle</td><td></td><td></td><td></td><td></td><td>$pinnacle<td>
</tr>
<tr>
<td>Protector</td><td></td><td></td><td></td><td></td><td>$protector<td>
</tr>
<tr>
<td>Triumph</td><td></td><td></td><td></td><td></td><td>$triumph<td>
</tr>
<tr>
<td>Union (UK)</td><td></td><td></td><td></td><td></td><td>$union<td>
</tr>
<tr>
<td>Victory</td><td></td><td></td><td></td><td></td><td>$victory<td>
</tr>
<tr>
<td>Vigilance (FR)</td><td></td><td></td><td></td><td></td><td>$vigilance<td>
</tr>
<tr>
<td>Virtue</td><td></td><td></td><td></td><td></td><td>$virtue<td>
</tr>
<tr>
<td>Zukunft (DE)</td><td></td><td></td><td></td><td></td><td>$zukunft<td>
</tr>
</table><br>
";
$timestamp = time();
$string .= date('F jS Y h:i:s A', $timestamp);
$string .= " EST</body>";
$fp = fopen('index.php', 'w');
fwrite($fp, $string);
fclose($fp);

As you can see, when the servers are up or down the result is a green or red text responce.

But what if I want to replace the text with an image? I've tried adding html with the image source, but I keep getting errors on the lines I've changed when running the php.

Is there a way to, easily, replace text with images? And when my feed calls for the $servername ($victory, $freedom, etc) that the image shows?

I'm a novice at coding, so any help would be appreciated.

Thanks.

myfayt
09-15-2011, 02:35 PM
So this doesn't work? I know it will on an echo, but a return?


if ($timeDiff >= "1") {
@fclose($handle);
return "<img src=\"green.jpg\">";
} else {
@fclose($handle);
return "<img src=\"red.jpg\">";
}

BlinkyBIll01
09-15-2011, 02:55 PM
So this doesn't work? I know it will on an echo, but a return?


if ($timeDiff >= "1") {
@fclose($handle);
return "<img src=\"green.jpg\">";
} else {
@fclose($handle);
return "<img src=\"red.jpg\">";
}

gah! what the hell is wrong with me? forgot to add the \ before and after the quotes. *slaps forehead*

Thanks! :)

myfayt
09-15-2011, 03:22 PM
Haha you're welcome, it happens to all of us. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum