tags:

views:

255

answers:

6

Hello all,

I have a test.php script which contains this:

<?php echo 'test'; ?>

When I point to it via my browser, it works and prints out "test" as expected.

I have another script which I am trying to test but however, it is ignoring all my echos! I thought I would put an echo right at the top as this will surely work, but when I get to this script via POST request from a form. It does not even echo out what is at the top of the line:

<?php echo 'START START START';

error_reporting(E_ALL);

I even point to from my browser and still no output?

What the hell is going on?

Update

The error log shows this :

PHP Parse error: syntax error, unexpected T_ECHO in /var/www/tester/convertor.php

But the echo is at the top of the line. I am going to set diaplay errors.

A: 

You're missing the ending ?>

<?php 
   echo 'START START START';
   error_reporting(E_ALL);
?>
rodey
The ending ?> is optional and recommended to not be used
Greg
That was just a snippet.
Abs
+4  A: 

Things to try:

  • Check your error log
  • Check the headers (is it coming back 404?)
  • Make sure you view-source: don't just look in the browser
  • Delete everything except the echo. If it works, add things back a bit at a time until it breaks.
  • Load your script in a hex editor and make sure there aren't any weird characters in there
  • Are you including this file from another file? If so, check the other file too. Watch out for output buffering.
Greg
-Delete everything except the echo. If it works, add things back a bit at a time until it breaks.This is exactly the procedure i use when something in a long code go bad and the page displayed blank
DaNieL
+2  A: 

Put exit; after the echo start start start and see if that works. Look in the apache error log for clues. Comment out the rest of the PHP code in the file and see if it works then...

UPDATE

I have had this when copy pasting white space from a browser sometimes - e.g. copy/pasting some code from a web page. Sometimes weird control characters get embedded invisibly in the white space, and I find that deleting the whitespace and re-entering it fixes it. Did you copy paste anything into this file?

Flubba
Error logs show this: PHP Parse error: syntax error, unexpected T_ECHO in /var/www/tester/convertor.php ??? Its at the top of line?
Abs
A: 

Are you hosting this page on a server with PHP installed?

If you just have a .php file on your hard drive somewhere and open it in a web browser, it won't work. You need to be running a web server with PHP extensions and access the file using the HTTP or HTTPS protocols.

sangretu
At my last job, I did a lot of PHP instruction. When a new designer came in, this was almost always the first problem.
Brad Gignac
Come on - I am not that thick!
Abs
The post opened with the fact that another script works as expected - that is not a particularly helpful suggestion, given the fact.
Flubba
+4  A: 

You have a parse error, so the script isn't even executed. So it's expected that it won't output anything.

The parse error can be for any echo in the script. It may be because of an "echo" statement after a line missing a semicolon, for example.

FWH
Thank you very much. I learnt an important fact today.
Abs
A: 

On a similar note to this i have seen alot of scripts throw errors like this when they have come from developers on windows (i'm on linux).

I have to go to the start of the php file and hit delete a couple of times to get rid of some invisible characters before the script will run.

Question Mark