I often test web files containing PHP on my local machine without a web server, at least until all basic style and HTML layout issues are resolved. Recently I began adding small PHP blocks to dynamically add some styling within HTML tags. I realize the PHP won’t run with no server, but I still always expect PHP open/close blocks to be ignored. But I’ve noticed that the trailing “>” symbols in PHP closing tags are displayed, when (1) the PHP blocks appear within an HTML tag *BUT
So can anyone tell me why or whether this behavior can be prevented? More important, is putting a PHP block INSIDE an HTML tag considered “invalid markup”? A short example (file is test [dot]php) appears below. When run from an actual web server there is no issue, but when run as a simple ‘file’ on a local machine, the unwanted “>” shows up anywhere PHP blocks appear WITHIN HTML tags. Note that renaming the file to “test.html” won’t alter the affect.
If anyone is curious, my reason for doing this is to dynamically add style attributes to certain container DIVs, to alter the way child IMGs are displayed. It DOES work flawlessly on every browser I’ve tried, but if the local machine test is revealing it to be invalid markup, I’d like to correct it.
[code=html]
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div <?php ?> > <!– trailing ‘>’ displayed. Why? –>
<br>test<br>
<?php ?> <!– ignored by browser –>
</div>
</body>
</html>