Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Aperture

macrumors 68000
Original poster
Mar 19, 2006
1,876
0
PA
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.

picture1xuz.png
 
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?
 
I don't think the validator validates PHP code. Not 100% sure but that would be my guess.

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.
 
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.
 
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.

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.
 
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?
 
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...

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?
 
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?

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.
 
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?

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.
 
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.

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.
 
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.

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. :)
 
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 and displayed the correct 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.

Thanks again. Headache avoided. :)

No problem. Visit MacRumors, save a Tylenol.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.