Forum Moderators: coopster
I usually don't give two squirts about validating my HTML, but I am building a site from scratch and have worked for hours tonight on getting it to validate as 4.01 Trans. Guess what? I did it!
I am also testing in Mozilla, Opera, NS4 and IE to ensure that the site works.
Everything looks good and W3C validator nails me on the TYPE statement in my calls to the scripts I use. No problem. I put in the text/cgi and that clears. I put in TYPE=PHP and I am validated.
I go back to testing with the browser, but now Mozilla doesn't display the PHP script output. IE, Opera work fine. NS4 just dies when it hits that part.
I have tried:
TYPE = "PHP"
TYPE = "php"
TYPE = "text/php"
No dice. I have scoured the internet looking for an example, but cannot find one.
Can someone shoot a non-HTML expert a lifeline? I checked the W3C site, but couldn't find specific info on it.
THANKS!
Can you post the offending statement?
PHP is all server processed. None of it(unless something goes wrong) is output back to the browser, so you shouldn't be trying to validate it. You should be running the page, getting the result, and validating that.
Here is the simple statement:
"<script src="idya/ad.php">
</script>"
The validator says I need a TYPE = statement in there. For the SSI CGI scripts I run I added TYPE=text/CGI and it worked.
I did some hunting and if I use TYPE = text/javascript it still works and Mozilla and NS4 like it.
From the snippets I found on the net TYPE = PHP should work, but doesn't in Mozilla or NS4.
Thanks again!
Have you tried replacing '<script language="php">...</script>' with '<?php php code goes here?>'? Either way, no browser or validator should ever see the PHP script code at all. It's server-side scripting, not client-side.
I've never once used <script> tags for my PHP, and I *always* validate my code. It works fine, because what needs to validate isn't whatever.php, it's the output from whatever.php that gets sent to the browser when someone requents whatever.php.
<added> maybe you want <?php include("idya/ad.php");?> </added>
I can understand that. I guess what I am asking is when you call a PHP script from an HTML page which TYPE = do you specify?
According to the validator you need to do this. For javascript it's text/javascript and for cgi it's text/cgi. What is it for PHP?
A simplyfied step-by-step guide of a request to a PHP script:
<html>
<head><title>AC</title></head>
<body><p>Aaron <?php echo "rocks!"?></p></body>
</html>
<html>to the web server.
<head><title>AC</title></head>
<body><p>Aaron rocks!</p></body>
</html>
A simplyfied step-by-step guide of a request to an HTML document containing javascript:
<html>
<head><title>AC</title></head>
<body><p>Aaron <script type="text/javascript">document.write("rocks!");</script></p></body>
</html>
<html>
<head><title>AC</title></head>
<body><p>Aaron rocks!</p></body>
</html>
As you can see both ways produce the same HTML document. In the first example processing was done by the server. In the second example it was the browser on the client side that executed the JavaScript.
Hope this helps.
Andreas
<Scripts> are for the browser to process, and are currently only useful with type="text/javascript". Of course that assumes that the included script actually is written in Javascript...
I think pgrote may have been lead astray by the fact that '<script language="php"> php code here </script>' is valid PHP syntax, as an alternative to '<?php php code here?>'. I don't know why anyone would choose to use that syntax, but it's listed as an option in the laguage reference portion of the manual.
Notwithstanding the fact that it's allowed, I think it's a bad idea. Using a <script> tag would make me expect the contents to be processed by the browser, not the server. In the case of PHP, that's wrong.
As Andreas said, you can't call a PHP file from an HTML file, because the server will skip the step of parsing and executing the PHP, so it never interprets your 'call', and the browser can't.
I didn´t know that <script type="php"></script> was a valid way of escaping PHP from HTML. Thanks for enlightening us.
I don't know why anyone would choose to use that syntax
I was wondering that too after I read your post. php.net has an answer [php.net] for that as well:
<script language="php">
echo ("some editors (like FrontPage) don't
like processing instructions");
</script>
Those script tags look exactly like the HTML ones, but they are not, since they are striped off by the PHP engine. Under normal circumstances no UA will ever see them.
Andreas