Question

so i have a php code to track my game server if it's online or offline. But i tried with html inside the echo but it outputs the famous T_String error.

My code:

    <table border="1" bgcolor="#fff">
  <tr>
<td>SERVER</td>
<?php
$fp = fsockopen("some ip", an port, $errno, $errstr);
if (!$fp)
{
    echo "<h1><td style="background-color:red">Offline</td></h1>";
}
else;
{
    echo "<h1><td style="background-color:green">Online</td></h1>";
    fclose($fp);
}
?>
</tr>
</table>

It says on line 26 which is echo "<h1><td style="background-color:red">Offline</td></h1>";

Was it helpful?

Solution

You need to escape those " inside the echoed string (and also remove the ; after else):

<table border="1" bgcolor="#fff">
<tr>
<td>SERVER</td>
<?php
$fp = fsockopen("some ip", an port, $errno, $errstr);
if (!$fp)
{
    echo "<h1><td style=\"background-color:red\">Offline</td></h1>";
}
else
{
    echo "<h1><td style=\"background-color:green\">Online</td></h1>";
    fclose($fp);
}
?>
</tr>
</table>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top