TomTees Posted November 28, 2010 Share Posted November 28, 2010 I have a file ("header.html") that predominately has HTML in it. This may sound silly, but I would like to rename it as a .php file so that when I add comments next to my PHP, my IDE will shade them gray. I just changed all of my PHP comments from // Some PHP comment to <!-- New and Improved PHP comment --> only to realize that PHP freaks out and doesn't treat them as comments - like NetBeans falsely does - but treats them as erroneous code. (Now I have to go back and fix all of my files back to the way they were?!) If I could change my file from "header.html" to "header.php" then all of my // Comments would be grayed out in my PHP blocks and make my code easier to read. To achieve that end, is it okay to rename a file from .html to .php even if most of the content is HTML and only a little is PHP? (BTW, could you have a file that has 100% html content saved as a .php file and still have it work properly?!) Thanks, TomTees Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 This: <!-- New and Improved PHP comment --> isn't a php comment at all. It's an HTML comment. Quote Link to comment Share on other sites More sharing options...
TomTees Posted November 28, 2010 Author Share Posted November 28, 2010 This: <!-- New and Improved PHP comment --> isn't a php comment at all. It's an HTML comment. I know that. And since it is an HTML file, I figured I could use them. But back to my question... TomTees Quote Link to comment Share on other sites More sharing options...
Sleeper Posted November 28, 2010 Share Posted November 28, 2010 You can call the file html htm or php and it will still act the same on the web. The only parts that matter are the coding of the page. Also to comment in php you would use <?php */ Comment */ ?> That works only in between the php start and ends. The normal html comments with the <!-- --> will work fine outside of the php tags even if on a php page. However if your doing all this just so you can read your code easier, I have no comment to that. Its just kinda well.... ya no comment. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 It is part of your question, since apparently you have them enclosed in php tags without echoing them into the html of the page. If they are intended as HTML comments, they need to be echoed like all of the other HTML. They cannot be used as php comments. If you rename .html files to .php extensions, the only thing that will be interpreted by php is what is inside <?php ?> tags. Everything else is ignored, and sent directly as output to the browser. Quote Link to comment Share on other sites More sharing options...
TomTees Posted November 28, 2010 Author Share Posted November 28, 2010 You can call the file html htm or php and it will still act the same on the web. The only parts that matter are the coding of the page. Okay, but to be more correct - as I found out last week - you can have 100% HTML in a PHP file and it ill run okay, but if you have any PHP in an HTML (by your webserver default) the PHP won't run. Right? Also to comment in php you would use <?php */ Comment */ ?> That works only in between the php start and ends. The normal html comments with the <!-- --> will work fine outside of the php tags even if on a php page. Same if it is an HTML file. That is where I screwed up. (Of course it didn't help that NetBeans tricked my into thinking I could do this... <?php <!-- Comment grayed out in NetBeans but invalid when code runs!! --> ?> However if your doing all this just so you can read your code easier, I have no comment to that. Its just kinda well.... ya no comment. Yeah, GOD FORBID someone actually tried to make their code WELL-DOCUMENTED and READABLE!! (What w-a-s I thinking?!) TomTees Quote Link to comment Share on other sites More sharing options...
Sleeper Posted November 28, 2010 Share Posted November 28, 2010 Okay, but to be more correct - as I found out last week - you can have 100% HTML in a PHP file and it ill run okay, but if you have any PHP in an HTML (by your webserver default) the PHP won't run. Right? Yes. You can edit your .htaccess file to runn php on a html/htm page, but that's for another day. If your have your answer now you can mark this post solved. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 Okay, but to be more correct - as I found out last week - you can have 100% HTML in a PHP file and it ill run okay, but if you have any PHP in an HTML (by your webserver default) the PHP won't run. Right? TomTees Not exactly. In the default configuration, that's correct. But additional file extensions can be specified to be parsed by the php interpreter in .htaccess or (if you have access to it) httpd.conf. Quote Link to comment Share on other sites More sharing options...
Sleeper Posted November 28, 2010 Share Posted November 28, 2010 Not exactly. In the default configuration, that's correct. But additional file extensions can be specified to be parsed by the php interpreter in .htaccess or (if you have access to it) httpd.conf. What I said but in a much more technical way of saying it..lol Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 Seems we were posting at the same time . . . Quote Link to comment Share on other sites More sharing options...
TomTees Posted November 28, 2010 Author Share Posted November 28, 2010 It is part of your question, since apparently you have them enclosed in php tags without echoing them into the html of the page. If they are intended as HTML comments, they need to be echoed like all of the other HTML. They cannot be used as php comments. If you rename .html files to .php extensions, the only thing that will be interpreted by php is what is inside <?php ?> tags. Everything else is ignored, and sent directly as output to the browser. So when you are building a website, is there any logical reason to name a file as HTML? (It seems to me that it would be easier to name HTML, HTML+PHP, and PHP files just as .php for simplicity?!) TomTees Quote Link to comment Share on other sites More sharing options...
Sleeper Posted November 28, 2010 Share Posted November 28, 2010 It's all good Pikachu. I'm a self taught newb. I'm not arguing with your responses...lol As far as naming files, I never use html anymore. It's just htm or php. If your aren't going to have php commands on a page then why name it php? You can but that's up to you. There is nothing wrong with having htm pages and then only naming the pages you have php on with the php extension. 99% of the people never never notice it, and 98% of the people going to your site don't know what an address bar is to find it anyways...lol Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted November 28, 2010 Share Posted November 28, 2010 For me, if a page has PHP code in it, it's a .php file. Makes things far easier that way. Keep in mind that regardless of file extension you use, your current context determines which comments will work. You can't expect HTML comments to work correctly in a PHP context, nor PHP comments to work correctly in an HTML context. Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted November 28, 2010 Share Posted November 28, 2010 To achieve that end, is it okay to rename a file from .html to .php even if most of the content is HTML and only a little is PHP? (BTW, could you have a file that has 100% html content saved as a .php file and still have it work properly?!) These are essentially the same question. Yes, it is perfectly okay. All the .php extension is doing is running that file, when called, through a program on the server that looks for code between "<?php" and "?>". If it doesn't find any, it simply passes it on. Granted, theres no point on naming a purely HTML file as a php file, but unless you're just serving up millions and millions of pageloads a day, you likely wouldn't notice the effect of sending a purely HTML file through the PHP parser. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.