html - Writing PHP in <head> -
is valid store php variables/values inside <head>
tag? there disadvantages or advantages writing php html in format? matter?
i sampled following code direct input through w3c validator:
<!doctype html> <html> <head> <title>php head test</title> <?php $data; ?> </head> </html>
and 1 error:
line 5, column 4: saw <?. probable cause: attempt use xml processing instruction in html. (xml processing instructions not supported in html.) <?php $data; ?>
but i'm guessing that's because it's validating .html
file has php code in it.
i planning use php store preprocessed mysql data variable use in javascript. <head>
proper place store these values?
note: not trying print out data in head, silly. asking storing preprocessed data mysql php (to used in javascript) in <head>
.
no, storing php variables in head not proper way it. in fact, when this, variables not stored inside head, php server side, html/css/javascript client side.
you want store variables before there html outputted.
however, if :
<head> <title>php head test</title> <?php $data; ?> </head>
it's not doing anything, if wanted display it, use echo. code absolutely nothing except declare $data if wasn't declared before-hand.
generally, should have of php code out of html file, should in different files , php code should include html file. in case, php code put in html file have access php variables available in file included.
Comments
Post a Comment