Validating a simple PHP statement

Discussion in 'Web Design and Development' started by Aperture, Aug 18, 2009.

  1. Aperture macrumors 68000

    Aperture

    Joined:
    Mar 19, 2006
    Location:
    PA
    #1
    I'm trying to validate a few lines of PHP using the W3C Validator and the Validator isn't happy. The doctype is HTML 4.01 Transitional.

    <?php

    echo "<tr>";

    ?>

    Below is a screenshot of the error. Does anyone have any ideas as to how I would go about validating this? Thanks a lot.

    [​IMG]
     
  2. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #2
    Dumb question, but are you sure the file is getting parsed by PHP? In other words, when you view it in a web browser, is it showing the echo command itself?
     
  3. SilentPanda Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #3
    I don't think the validator validates PHP code. Not 100% sure but that would be my guess.
     
  4. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #4
    If accessing via a web page, not just copying/pasting code, I don't see why it wouldn't work, since PHP would parse the file and output HTML code.
     
  5. SelfMadeCelo macrumors regular

    SelfMadeCelo

    Joined:
    Sep 9, 2008
    Location:
    Tulare, CA
    #5
    Yeah the W3 Validator won't validate PHP. I'm assuming you're trying to validate the final output of HTML. That <tr> could've not been needed or never closed. Hard to know without the rest of the HTML.
     
  6. SilentPanda Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #6
    Well yes, in that case it should work. However I think the OP is feeding the raw PHP into the validator and not the generated HTML from the PHP.
     
  7. Aperture thread starter macrumors 68000

    Aperture

    Joined:
    Mar 19, 2006
    Location:
    PA
    #7
    Hi guys, thanks for the responses. No, that snippet is part of a larger HTML page... and just that little section is not validating. It is being parsed as PHP...

    Edit: So should I just comment out all the PHP, validate it, and call it a day? If it won't validate PHP, is that as far as I can go?
     
  8. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #8
    So, you're not seeing the echo statement when viewing the page manually? This doesn't seem right since the validator should only see HTML. Are you copying/pasting the PHP code into the validator?
     
  9. SelfMadeCelo macrumors regular

    SelfMadeCelo

    Joined:
    Sep 9, 2008
    Location:
    Tulare, CA
    #9
    It's not that it's not validating the PHP...it's not validating the final HTML that the PHP is producing. Post the final HTML and we can get to the bottom of it.
     
  10. Aperture thread starter macrumors 68000

    Aperture

    Joined:
    Mar 19, 2006
    Location:
    PA
    #10
    I built the whole page, with the PHP snippets, and had it saved. I simply selected every bit of text in that file and pasted it into the validator.

    If I view the page in Safari, it parses the echo statement correctly (as in, it doesn't actually print "echo" on the screen, it instead inserts a table row as intended).

    I'll upload the whole page in a few minutes... stay tuned.
     
  11. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #11
    That's the problem then. You are pasting PHP code into an HTML validator. Have the validator check your site through the web server. There's no need to upload any files.
     
  12. Aperture thread starter macrumors 68000

    Aperture

    Joined:
    Mar 19, 2006
    Location:
    PA
    #12
    Wow, that makes perfect sense. Thank you to everyone that responded.

    I wasn't even thinking that if I gave the validator a URL, it would have already parsed the PHP serverside and displayed the final HTML. Just as you said, the way I've been doing it, it isn't interpreting the PHP as PHP, and tried to validate it as HTML.

    Thanks again. Headache avoided. :)
     
  13. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #13
    No problem. Visit MacRumors, save a Tylenol.
     

Share This Page