开发者

Why will this text in the browser source code not show on the screen?

I am modifying an existing source code viewer script in PHP that I found on the web. It is to store source code in a nice category fashion.

I am having a problem now though. Below is a screen shot of me viewing the source code in Firefox, you can see the part that is supposed to show on the screen but for some reason it is not showing on the screen, it is开发者_开发百科 showing up in the source of the page though so I am really confused as to why I cannot view it in the browser? You will also notice that the text color is Pink/Purple color. The part inside the

Please not that it is not any CSS that is making it hidden or anything.

alt text http://img2.pict.com/cd/d2/74/2663869/0/screenshot2b209.png


<?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.


Processing Instructions are not shown in the browser.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜