有人可以向我解释如何得到一个.php文件,该文件使用文件开头的shebang来传递XHTMLvalidation器? 我不断收到一个错误,指出我必须将xml utf-8声明放在文件的开头。 当我这样做时,我必须从第一行删除我的shebang。 因此,服务器无法读取我的文档,我得到一个错误。 例如下面的文件不通过XHTMLvalidation:
#!/usr/local/bin/php <?= '<' . '?xml version="1.0" encoding="utf-8"?' . '>' ?> <?php $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"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >
将服务器configuration为删除shebang行,或者将服务器configuration为通过PHP解释器parsing.php文件,然后删除shebang行。
我从来没有遇到一个服务器(据我所知)甚至能够使用shebang线,所以我甚至不能想象你用什么来提供比这更多的描述。 如果您在post中提供更多详细信息,或许有人在使用您的经验,可以给您一个更好的答案。
你想validation原始的PHP源代码,或脚本执行的输出? 我会怀疑后者会更有用,在这种情况下,唯一要担心的就是这个shebang是否在脚本输出中结束了。
你可以发布你如何执行PHP脚本(例如,是否从命令行/定期脚本或Web请求调用)?
/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)
看起来你有一个空行,在你之前的第一行<?= 。 不要这样做,输出空白行,所以你的XML文件将以空行开始,而不是<?xml ...?>