Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the W3C Validator not take <?php include() tags in HTML5?

I was trying to validate a simple HTML5 page, and it successfully validates everything except three instances of <?php include statements which are marked as errors. I can't figure out what makes it not take the PHP tags. Why would this be? Below are the three errors it outputs:

Validation Output: 3 Errors

 Line 29, Column 5: Saw <?. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)
            <?php include("inc/main-menu.php"); ?>

 Line 87, Column 9: Saw <?. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)
        2007-<?php echo date("Y"); ?> 

 Line 94, Column 3: Saw <?. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)
    <?php include_once("inc/analytics.php"); ?>
like image 264
Glen Selle Avatar asked Dec 04 '22 07:12

Glen Selle


2 Answers

Those PHP tags should not show up in your markup. They'll be written in your code, but only your web server should see those -the page generated by your server will not have those tags visible.

I'm guessing you are copying your source and pasting into the validator? Try viewing the page in your browser instead (assuming you are running a local web server, like Wamp or Xampp), view source, and then copy and paste that code, instead of directly from your editor.

like image 122
Philip Schweiger Avatar answered Mar 02 '23 00:03

Philip Schweiger


<?php is not valid HTML in any dialect. An HTML parser should never see <?php tags, since they're evaluated on the server. As such, it's correct that the validator complains.

like image 40
deceze Avatar answered Mar 01 '23 23:03

deceze