Simple PHP echo code not working

edorahg picture edorahg · Oct 3, 2011 · Viewed 95.7k times · Source

Here is my html with a php script:

  <html>
      <head>
    <title>Bob's Auto Parts</title>
  </head>
  <body>
    <h1>Bob's Auto Parts</h1>
     <table width = 100% >
         <tr>
             <?php
                 echo "<td>This is working.</td>";
             ?>
         </tr>
     </table>
  </body>
 </html>

Why is the output of this appearing with a ; ?>. I want it to be 'This is working.' only. Here is the ouput

Bob's Auto Parts

Bob's Auto Parts

This is working."; ?>

I know I am doing something wrong here but not able to figure it out. Thanks in advance.

Answer

Kirk picture Kirk · Oct 3, 2011

Make sure that you are using <?php and not <? shorthand since that may be disabled on your server. This will cause the output of "; ?> as it happened to me a few months ago in a transition to PHP5.

I've only seen the odd output like this when the PHP parser isn't detecting it as PHP. Make sure to check that PHP is functioning as expected and that the <?php tag is being recognized.