/    Sign up×
Community /Pin to ProfileBookmark

Any problems with the phtml file extension?

In a previous thread, I mentioned that my host will not allow us to scan for php in files with the .htm extension. So files with a php htm mix need to have a different extension.
After looking at the situation for a while, the best option seems to be to use the .phtml extension for all the files ( not phtm, the L on the end makes a difference!).
index.phtml
page1.phtml
and so on.
The phtml extension seems to be recognised by the widest number of editors, browsers and interpreters as both php and html, but before I go ahead an adopt that extension, does anyone know of any browser or editor that does not correctly recognise the extension? Or of any other problems?

to post a comment
PHP

21 Comments(s)

Copy linkTweet thisAlerts:
@pyroJul 11.2005 — I didn't read your other thread (because you didn't link to it, and I didn't want to go search for it) but why can't you use .php? The extention is rather irrelevant, as long as the server parses it as application/x-httpd-php, .phtml doesn't mean HTML+PHP any more than .php... I use .php as it certainly is the most common extention for PHP documents (thus making the code more likely to work on more servers).
Copy linkTweet thisAlerts:
@SuzanneBauthorJul 11.2005 — If you are saying that phtml does not meant php+html, then there is no real reason to use the extension phtml.

Really the documents are not php, they just contain some very small elements of php. You wouldn't call an html document .js because it has one line of Java Script in it. Equally, I did not want to call the documents .php because they have one line of php in them.

The main difference is that most editors consider .php documents to "code" rather than html and treat them differently.

I thought that phtml WAS a mix of the two, consequently would be OK, but you seem to be telling me that is not the case.
Copy linkTweet thisAlerts:
@SuzanneBauthorJul 11.2005 — Oh, I forgot to say that an important difference between the two extensions is that IE will display a .phtml source file but it will not display a .php source file. ( in other words a file that has not been processed by the php interpreter) It displays a .phtml as an html file, missing out any php found inside. This is very handy, if your file is largely html. This is also true of Firefox, which will happily display a .phtml
Copy linkTweet thisAlerts:
@pyroJul 11.2005 — If you are saying that phtml does not meant php+html[/QUOTE]I'm saying the .phtml means nothing special (nor does .php, really). It all depends what the server is set up to parse as PHP (usually .php, somethind other things as well, such as .phtml or simply .html documents).

Really the documents are not php, they just contain some very small elements of php.[/quote]That's irrelevant. If it contains ANY PHP code at all, the document needs to be interpreted as PHP, so the code is executed. Since most servers are not set up to parse .html files as PHP code, you have to use an extention that is.

You wouldn't call an html document .js because it has one line of Java Script in it.[/quote]That's a non-issue, as JavaScript is interpreted on the client side.

I thought that phtml WAS a mix of the two, consequently would be OK, but you seem to be telling me that is not the case.[/QUOTE]I'm saying that BOTH are (or can be) a mix of the two, and the .phtml needs to be processed the same as .php. I really don't care which extention you use, I just use .php for portability.
Copy linkTweet thisAlerts:
@SuzanneBauthorJul 11.2005 — The fact that IE and Firefox both attempt to display a .phtml as .html is a great feature of that extension.

However, I think you have won me over. Portability is a more important issue. In fact it is portability providing the motivation for this change. My first thread stated that I had used .htaccess on an Apache server to tell it that I have php in .htm files. The problem is, on a new server, the .htaccess is prohibited, so the .htm files are not being processed. I wanted to know what extension I should choose to get everything working.

Hmm.
Copy linkTweet thisAlerts:
@ScleppelJul 11.2005 — IE and Firefox will do the same to .php files if you attempt to open one with them. You can also make it automatic for .php files to open in IE/Firefox just like .phtml. All you have to do is right click on a .php file, go to "Open With" > "Choose Program..." > Select Firfox/IE, tick the "always use the selected program" tickbox or whatever it is and then click OK. And you're done.
Copy linkTweet thisAlerts:
@SuzanneBauthorJul 11.2005 — I don't think you follow what I mean.

In IE and Firefox, the way they display a php and phtml is completely different.

Basically, if you display a php it will just display the source. If you display a phtml it displays the result, not the source.

The reulst being the displayable part of the html - not the php of course.
Copy linkTweet thisAlerts:
@ScleppelJul 12.2005 — Oh, sorry. It doesn't do that on my computer...
Copy linkTweet thisAlerts:
@BeachSideJul 12.2005 — I don't think you follow what I mean.

In IE and Firefox, the way they display a php and phtml is completely different.

Basically, if you display a php it will just display the source. If you display a phtml it displays the result, not the source.

The reulst being the displayable part of the html - not the php of course.[/QUOTE]

php has nothing to do with the browser... hence it is a server side language.
Copy linkTweet thisAlerts:
@legendxJul 12.2005 — you can never see the php source if it is being interperted by the php server. .php and .phtml are both interperted the same way
Copy linkTweet thisAlerts:
@bokehJul 12.2005 — The fact that IE and Firefox both attempt to display a .phtml [/QUOTE]The whole point of a php file is that it a parsed. You don't want browsers opening php files but if a client saves one from a website it will automatically add the htm extention.

There is no reason why you can't name all your files .php though even if they are just html with no php inside.
Copy linkTweet thisAlerts:
@felgallJul 12.2005 — phtml doesn't mean PHP+HTML it means embedded PERL file - see http://filext.com/detaillist.php?extdetail=PHTML
Copy linkTweet thisAlerts:
@SpectreReturnsJul 12.2005 — Actually, [dot]phtml is a depricated PHP extension, replaced by usually [dot]php.

SuzanneB: If [dot]phtml and [dot]php files are showing up differently, that means your server is not parsing one of them. It has nothing to do with the browser.

Your point about one line of js not being a [dot]js file is only true because [dot]js is meant ONLY for JavaScript, where as PHP is handled by the server and returns the output.

As for the problem of your server not detecting index.php, you can use index.html and

a) use javascript to cloak to the index.php (not recommended)

b) use the meta refresh header

c) use a frame (not recommended)

d) use an iframe

These will all work, but cloaking is a bad technique to do, and frames are frowned apon.
Copy linkTweet thisAlerts:
@bokehJul 12.2005 — Why not just move to a server that is set up properly.
Copy linkTweet thisAlerts:
@SuzanneBauthorJul 12.2005 — Oh dear heaven!

Sorry, but I don't think anyone got what I was saying, which means I must have said it all wrong. Hmm...not an easy thing to describe. But I am talking about dropping the un-parsed code into IE and seeing how it handles the file type.

Oh, anyway, I have decided not to use the phtml extension, so it's not to worry. Sorry I confused everyone. :-(
Copy linkTweet thisAlerts:
@BeachSideJul 13.2005 — We realize excatly what you are talking about and are all saying it cannot be done.

I don't care what browser you use, they will all display the same in regards to a .php file. PHP is parsed by the server not the browser. Same goes for .phtml.
Copy linkTweet thisAlerts:
@SuzanneBauthorJul 13.2005 — I hate to tell you beachside, you don't understand what I was talking about, because your comments are way wide of the mark! But I hasten to add that it was my fault, I confused everyone, but trust me, I do know what I am doing with those files even though I don't know what I am doing when it comes to explaining what I did with them! Ha ha!

The bit about displaying them in IE and Firefox was just for development purposes, but I am not going to even try to explain it again. It's one of those things that if I showed you, you would get in an instant, but explaining it, everyone has a fixed idea in theor heads that I can't shake with words. Suffice to say that when I am viewing the files in IE and Firefox, they are not on a server.

Anyway! Enough! I have confused everyont too much!!

As I said, I have decided to change everything from htm to php and not use phtml.

:-)
Copy linkTweet thisAlerts:
@BeachSideJul 13.2005 —  Suffice to say that when I am viewing the files in IE and Firefox, they are not on a server.
[/QUOTE]


I don't care what browser you use, they will all display the same in regards to a .php file. PHP is parsed by the server not the browser. Same goes for .phtml.[/quote]

I'll type real slow...

If the server is NOT parsing the code that is contained within the file then the results cannot be displayed. Therefore if you do not have them located in a directory that is conatined on a server (ie your desktop) and open the file, no matter what browser you use it will only display the source code.

If that is not what you are talking about then yes I agree you did not explain your issue very clearly at all.
Copy linkTweet thisAlerts:
@SuzanneBauthorJul 13.2005 — Nearly there!!!!!

Except, if you use the .phtml extension, box IE and Firefox do not just display the source code. They display the files as if the content is html.

You may wonder why that is important. It just happens to be handy if the php content is small and you want a quick idea of what the html looks like. Just drop it in the browser and it displays the result of the html and ignores the php.

:-)
Copy linkTweet thisAlerts:
@SpectreReturnsJul 14.2005 — Doesn't .html do that?
Copy linkTweet thisAlerts:
@BeachSideJul 14.2005 — Yeah but .phtml doesn't actually output the php code to the display, you can only see it if you look at the source. After their last post it was made clear that this was what they were wanting it to do.

Make a file that would be previewed without a server.

This file is going to have PHP code in it.

Display the file without the PHP code being displayed so as to not mess up the display of the page.

Not have to change the file extension for all the files when they upload the files to the server.

Now if that would have been presented I would have said make .php files and comment out the php code with...
<i>
</i>&lt;!--
&lt;?php
... some php code ...
?&gt;
--&gt;
×

Success!

Help @SuzanneB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...