Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PHP echo code not working

Tags:

php

echo

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.

like image 976
edorahg Avatar asked Oct 03 '11 18:10

edorahg


People also ask

Can you echo PHP code?

You cannot have PHP echo more PHP code to be evaluated because PHP interprets your code in a single pass.

What is echo in PHP with example?

Description ¶ echo(string ...$expressions ): void. Outputs one or more expressions, with no additional newlines or spaces. echo is not a function but a language construct. Its arguments are a list of expressions following the echo keyword, separated by commas, and not delimited by parentheses.


2 Answers

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.

like image 51
Kirk Avatar answered Oct 08 '22 15:10

Kirk


Any of these (or more) could be your answer why it is not working

  1. Is there actually PHP running on your computer?
  2. Is the file extension .php?
  3. Are you accesing the file through your browser doing something like http://localhost/myfile.php
  4. If it is on a remote server, is there PHP installed?
like image 36
Rene Pot Avatar answered Oct 08 '22 15:10

Rene Pot