I'm with Tony, using PHP shouldn't make any difference if everything is done correctly, even doing little echoes everywhere like you are doing.
You can compare the output of the PHP page to the regular HTML and see what's different, that should give you a clue to what's going wrong.