Is it necessary to have
on a page ending with *.php and that has absolutely no markup in it?
Is it necessary to have
No, the tags are only required to actually parse php code.
If you don't have them, it assumes you want the contents printed out rather than executed. You can include() a file with no php tags but it's probably not what you want.
From http://nl3.php.net/manual/en/function.include.php :
I think you got it wrong, mathiaus.
If you use php code, you need the php-tags. Even for
Me, wrong??? Never!
Your code uses the php function echo to display hello. You could simply just type hello and rather than php parsing the echo function, it will just serve the text provided (as HTML).
Just because the file extension is php doesn't mean that php has to be used, plus the question mention that there was no markup!
Mathiaus is quite right here, TomS.
Of course, polly-gone, you would end up with a somewhat empty file if it had no markup in it and no PHP (unless you're including other forms of text as something else).
If you want PHP to execute, regardless of filetype, you will need those tags, and the PHP must be within them. This holds true even if there is no extension and you're using a hashbang + trying to execute the script via a command-line interface.
these tags are only used to mark PHP codes.
you dont have to use them, if you havent written PHP codes.
both usages are true. just use <?PHP ?> tags, only when you are writing PHP codes.
No, he's not
The actual question was:
Is it necessary to have PHP tags on a page ending with *.php and that has absolutely no markup in it?
Markup is html. Php is not a markup language.
So the answer to this question is: Yes, you need php-Tags, even if the file-extension is .php and even if you're using only php-code and no html-code.
I don't know enought English and I cannot say who is right and who is wrong. But if I good understand question then you can use .php extension on plain html page (page without any type of php script - echo, include, session, etc.). I am always creating plain html pages with .php extension because I never know would I like to put some php in this pages after some times. The main reason for this practice is SEO and indexing in search engines.
The only thing you need in above case is to send appropriate headers or by any other possible way tell the browser that the requested file is js.
No you can also only start with <? and don't close if short tags are allowed by your php settings
actually not closing the php tags is a better idea most of the time. That way you won't accidentally have white lines giving you the infamous "headers already send" error.
Header already sent is caused by rubbish before the Header() function of Php.
So there's now problem with that.
While the code without closing the tag procudes an parsing error.
I've never come across the idea of not closing the Php-tags and I just don't see the point
Notice how there is a whiteline in the include file, which will be seen as output and send to the browser. Because output is send to the browser, the headers will also be send, and because the headers are already send the "session_start" function will throw a "headers already send" error.
This would not have happened if the include file didn't have the php closing tag. Instead of sending the whiteline, the whiteline would be seen as part of the php and just ignored.
Now in this small part it is easy to detect, but think of a big file ending with "?> " (including the space after the tag), that would also throw the same error and would be a pia
Alright. In that case... I see your porint.
I usually write <?php ?>, then save the file and then insert my code in between the php-tags. It's unlikely for me to produce unwanted output that way.