A: 

Processing Instructions are not shown in the browser.

Ignacio Vazquez-Abrams
+2  A: 

<?php is considered as an opening tag, which is only closed by ?> ; and the browser doesn't display tags themselves.

The <td> tags, for instance, are not displayed by your browser : they are interpreted to create a table ; it's the same with the <?php tag... But it doesn't generate any output, as the browser doesn't know what to do with it.


If you want to actually display your portion of PHP code in the HTML page, you have to encode it to HTML entities :

  • < should be converted to &lt;
  • > should be converted to &gt;
  • & should be converted to &amp;
  • " should be converted to &quot;

This way, you'll get some valid HTML, and not "things looking as HTML tags".


But note that if you want that portion of PHP code to actually be interpreted (So the query to the database is executed, and generates some output), you'll have to re-configure your webserver, so PHP code is interpreted : you should not see the PHP code on the browser-side.

Pascal MARTIN
Ok I see so I should run htmlentities() to show the php to the browser, thanks
Jack Ferrari
You're welcome :-) (htmlspecialchars should be enough ; but htmlentities should work too :-) )
Pascal MARTIN
To be more precise, browsers are designed to *ignore* HTML tags they don't know. The alternative would be to trigger an error message and stop rendering the page and it was not considered a good idea on early days.
Álvaro G. Vicario
A: 

That is not "browser source code". It is PHP source code that superficially looks like HTML. This is not a petty distinction, but actually fundamental if you want to understand how things work. If you are viewing that exact code in Firefox, it means you're viewing the PHP as text, not rendered HTML.

So something is wrong with your PHP server setup.

Matthew Flaschen
It is supposed to show as PHP "text" it is for a sourcecode viewer project but it should show as html
Jack Ferrari