You've basically found an edge case of string interpolation. While alphanumeric array keys need to be quoted in PHP, in double-quoted strings they need to be unquoted:
echo "<p>This is my awesome User Agent: <b>$_SERVER[HTTP_USER_AGENT]</b></p>";
String parsing follows its own rules. In general, you can't drop random PHP code inside a string and get it executed.