RE: [PHP] Include File Errors with Comments
From: Patrick Moloney I have a simple web site with a simple page that all works well, although I have had a similar problem a couple of times that seems to be caused by Comment Lines in the included files. I wonder if I have it entirely right. All my files are .php files, but almost all the code is HTML. The file for my Web page is a complete HTML document, the file is .php. The web page file Includes a few other files by putting the Include statement in PHP tags, all by itself. The problem file contains the menu as the include. I made a change to the menu, that works, but I added a line with a comment at the top, which causes problems. The menu is read like text. The first few lines in my menu file, menu.php, are comments using HTML syntax. The menu file has on UL and LI tags for the menu items - no HTML, BODY etc. So I have a line of PHP in my web page file calling a .php file where the first 2 lines are HTML comments. It was working with 2 comment lines, the failed with 3 lines. Even when it fails the remainder of the page displays ok although it is down lower because of the menu being displayed as text. I remove the comment it works. Does PHP preprocess the file but treat the comments as text because I never said it was HTML? Would PHP comments have to be inside PHP tags? Am I correct in having just a fragment of HTML in the included file without the entire HTML organization? I'd like to have comments in the file. This is one detail that I have not seen a good explanation for. When PHP opens an included file, it defaults back to HTML mode. You must have the PHP tags to force it into PHP mode. This is true no matter what file extension you have on them. So if you want to use PHP style comments, you must wrap them with the proper tags. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include File Errors with Comments
Patrick Moloney wrote: Does PHP preprocess the file but treat the comments as text because I never said it was HTML? I've not had it do that. Would PHP comments have to be inside PHP tags? Yes. If you use a php comment it has to be inside a php tag. One issue I have seen though is xml/xhtml files. php sometimes sees the ?xml and assumes it is a php start tag. I assume the appropriate thing to do is turn off short tags in your php.ini file - but unfortunately a lot of 3rd party classes and apps make heavy use of them. Am I correct in having just a fragment of HTML in the included file without the entire HTML organization? I'd like to have comments in the file. Use html comments and it should be fine - or put php tags around the comments. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include File Errors with Comments
Patrick Moloney wrote: I have a simple web site with a simple page that all works well, although I have had a similar problem a couple of times that seems to be caused by Comment Lines in the included files. I wonder if I have it entirely right. All my files are .php files, but almost all the code is HTML. The file for my Web page is a complete HTML document, the file is .php. The web page file Includes a few other files by putting the Include statement in PHP tags, all by itself. The problem file contains the menu as the include. I made a change to the menu, that works, but I added a line with a comment at the top, which causes problems. The menu is read like text. The first few lines in my menu file, menu.php, are comments using HTML syntax. The menu file has on UL and LI tags for the menu items - no HTML, BODY etc. So I have a line of PHP in my web page file calling a .php file where the first 2 lines are HTML comments. It was working with 2 comment lines, the failed with 3 lines. Even when it fails the remainder of the page displays ok although it is down lower because of the menu being displayed as text. I remove the comment it works. Does PHP preprocess the file but treat the comments as text because I never said it was HTML? Would PHP comments have to be inside PHP tags? Am I correct in having just a fragment of HTML in the included file without the entire HTML organization? I'd like to have comments in the file. If you're putting php comments outside php tags, they are treated as text (they're not inside php tags, it's not php). The php tags tell php when to start parsing/processing the script. Without that, it passes it to your webserver to just display the content. If that's not what you're doing post a short (very short - don't post your whole scripts) example of what you mean. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php