HTML/PHP Symbol ≈ Outputting as ≈

只谈情不闲聊 提交于 2021-02-05 06:48:25

问题


I am prefixing some names in a table with "≈" so it would look like ≈Name

The output however is ≈Name

$name = '<span style="color:white;">≈</span>'.$name;

Is the code that I am using. Is there a way I can escape this and get the actual ≈ to display?


回答1:


It could be a header problem or a text editor problem.

You may need to send UTF-8 headers. In PHP, before sending anything to the user, try this...

$header_text = 'Content-type: text/html; charset=utf-8';
header($header_text);

This is the preferred solution.

Also, some browsers will also respect an HTML tag in the header of the HTML, like this...

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

I usually combine these two approaches.

Of course, in certain situations (PDF generators, excel sheet generators, etc.), neither of these solutions may be applicable, and you'll need to make your source code ugly to solve it, with HTML entities...

$name = '<span style="color:white;">&#8776;</span>'.$name;

You will also want to verify that your source code file is actually encoded as UTF-8. Different text editors will have different options in handling charsets. So, the problem could possibly be your text editor not saving correctly.



来源:https://stackoverflow.com/questions/52558742/html-php-symbol-%e2%89%88-outputting-as-%c3%a2-%cb%86

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!