-1

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>";

user3215687
  • 3
  • 1
  • 2
  • Escape double quotes when encapsulated with double quotes `echo "

    Offline

    ";` or use single quotes `echo "

    Offline

    ";` Or.. or... or. There's another way, but this will suffice; for now. Oh, and the semi-colon in `else;` remove it.
    – Funk Forty Niner Jan 20 '14 at 15:36

1 Answers1

1

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>
Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80