This must be because there are various ways of starting a block of PHP code:
-
<? ... ?>(known asshort_open_tag) -
<?php ... ?>(the standard really) -
<script language="php"> ... </script>(not recommended) -
<% ... %>(deprecated and removed ASP-style tag after 5.3.0)
Apparently, you can open a PHP block one way, and close it the other. Didn’t know that.
So in your code, you opened the block using <? but PHP recognizes </script> as the closer. What happened was:
<?php <----- START PHP
</script> <----- END PHP
?> <----- JUST GARBAGE IN THE HTML