Take the 2-minute tour ×

Can someone explain to me how to get a .php document that uses the shebang at the beginning of the file to pass the XHTML validator? I keep getting one error that states that I have to put the xml utf-8 declaration at the beginning of the file. When I do that I have to remove my shebang from line one. As a result, the server cant read my document and I get an error. For example the below file does not pass XHTML validation:


<?= '<' . '?xml version="1.0" encoding="utf-8"?' . '>' ?>


  $strLessonDescription = file_get_contents('http://example.com/.../lesson5.txt');

  if ($strLessonDescription  == NULL)
     print "Error - lesson5.txt cannot be opened";

  $arrLessonVocabulary = array();

  $arrLessonVocabulary = file("http://example.com/.../vocabulary5.txt");

  if ($arrLessonVocabulary == NULL)
     print "Error - vocabulary5.txt cannot be opened";  


share|improve this question

4 Answers 4

up vote 2 down vote accepted

Either configure your server to remove the shebang line, or configure the server to parse .php files through the PHP interpreter and then remove the shebang line.

I've never encountered a server that (to my knowledge anyway) is even capable of using that shebang line, so I can't even begin to imagine what you're using to offer anything more descriptive than this. If you provide more detail in your post, perhaps someone with experience in what you're using can give you a better answer.

share|improve this answer
Thank Kromey. It was worth a shot. I will just have to leave it as is for now. . . I think we just have a weird set up at UMUC. Thanks for being willing to help:) –  Mike Apr 15 '11 at 20:44

It looks like you have a blank line after your shebang line but before that first <?=. Don't do that, that blank line is output, so your xml file will start with a blank line instead of <?xml ...?>

share|improve this answer
It gets it pass validation; however, then it wont work when I pull up the browser. Thanks DerfK. I think the best way might be to just validate it as a html file first then to add the php language. –  Mike Apr 16 '11 at 17:45
 /usr/local/bin/php -l file.php
 will parse the file for any errors

 /usr/local/bin/php file.php | xmllint
 will parse the output from your php script (that is the xhtml)
share|improve this answer
Okay. Thanks for the info Silviud. –  Mike Apr 16 '11 at 17:43

Are you trying to validate the raw PHP source, or the output from the script execution? I would suspect that the latter would be more useful, and in which case the only thing to worry about would be whether the shebang is ending up in the script output.

Can you post how you are executing the PHP script (e.g., whether it is being invoked from a command-line/periodic script or a web request)?

share|improve this answer
I have the php script included in the xhtml file within the <?php and ?> tags. So you think maybe the way to get it validated is to just seperate the pages(.html and .php page)? That actually sounds like a good idea. I will give it a try and see what happens :) Thanks for the heads up! –  Mike Apr 16 '11 at 17:19
The file is downloaded on the UMUC servers under the cgi-bin. I invoke it by means of the url in a browser. –  Mike Apr 16 '11 at 17:20
Ah, that makes sense. The tricky part about your issue is that what you are trying to validate is not what a browser will ever see. In other words, you don't have to worry about whether the shebang is W3C standards-compliant, because that line will never be displayed in the browser (ideally!). So as long as you validate significant permutations of the output of the code, you should be in good shape (for example, if lesson5.txt or vocabulary5.txt are not found, the script in your OP will output non-compliant markup [because the error message will be output before the doctype]). –  user70463 Apr 17 '11 at 17:35

Your Answer


