PHP在回显HTML时打印HTML符号

How can I use HTML symbols when printing HTML with PHP?

For example:

<?php
   echo "<p>here is a symbol &bull;</p>";
?>

The &bull; is an HTML symbol for bullet: http://www.w3schools.com/tags/ref_symbols.asp.

I currently see "here is a symbol &bull". I expect to see "here is a symbol •".

Your code doesn't look like it has problems at all. But there are a few things you can do:

  • Copy the bullet point symbol from somewhere else, and directly paste it in your code (not recommended)
  • Check the source code of your page, and see what you get. If you have &amp;bull, then you know you've got an error. Try rendering using single quotes or print <<<HERE HERE;.
  • Check if your code really is exactly that. Any subtle changes might make a difference.

The issue here is not this particular line of code you have provided. Likely this is a problem with your PHP environment. You may have and extension that automatically translates all html entities. PHP processing takes place on the server's side. HTML processing is done client side once your browser receives the code. This would mean that once PHP has done it's processing the resulting string is &amp;bull. You will need to look into your PHP configuration. One setting to check is default_mimetype which should be 'text/html'.