php特殊字符不解码

时间:2012-10-19 14:04:28

标签: php special-characters html-entities

我通过表单输入在teo php页面之间传递一些字符串。字符串有HTML特殊字符(á,é,í,ó,ú,ñ),我需要它们才能正确显示。

这是我的表格:

<form action="test.php"> <input type="text" name="message" style="" value="" /> </form>

这是test.php:

$message=htmlentities($_POST['message']);

我的目标是实现$ message包含与键入方式完全相同的特殊字符: 例如,如果表单中的字符串是:'áñ'我想要$ message ='áñ'而不是他们的html等价物,“&aacute;&ntilde;

编辑:

如果我这样做,那么完全清楚:

echo $ message = htmlentities($ _ POST ['message']);

borowser正确显示áñ,但php变量包含“&aacute;&ntilde;”。我希望php变量是áñ,而不是“&aacute;&ntilde;”;

iv尝试应用htmlspecialchars_decode; utf8_decode和其他一些php函数,绝对没有运气。 some1可以帮帮我吗? 感谢

1 个答案:

答案 0 :(得分:0)

确保在包含表单的HTML页面中添加正确的字符集。

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

如果您使用的是PHP页面,请将以下内容放在文件的顶部:

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