If this code is included as is on the live server, it gives me a 500 error. If I change the leading <?php to just <?, it runs, but produces crazy results. I was beginning to think I lost my mind on how to embed php code in html.
To debug, I used Chrome debugger, it steps through & gives me all kinds of nonsense things, but one key I noted is that in view source the php code (above) is in a green shade of text.
When I run this exact same code on my trusty development server, it works as intended.
Images attached show result of IDENTICAL code on both servers. One called bad is the one that does crazy things.