<head>
<meta charset="ISO-8859-7">
</head>
我一直在使用表单,并看到<meta charset="ISO-8859-7">
标记对将在文本区域内输入的文本进行编码。这是用来存储文件的编码方法不是。字符如何通过表单传输?
我已经看到了,如果键入的字符不是由<meta charset="ISO-8859-7">
标签speciefied编码的一部分,该角色会是referenced(& #D;)
我假设的形式发送的字节来自编码规范的序列。 因为如果我键入一个字符无论它是什么,将是一个编码将解释的字节。
例如与<meta charset="ISO-8859-7">
i的一个形式的字符"¥"
这炭类型不是编码的一部分,但它必须发送作为它代表A5
,如果不管位置的字节可以表示(这通常由任何编辑器进行)。
但是不是,表单不会将它作为字节发送,而是字符为referenced。
代码:
的index.php:
<?php header('Content-Type: text/html; charset=ISO-8859-7'); ?>
<head>
<meta charset="ISO-8859-7">
</head>
<form method="post" action="encode.php" accept-charset="ISO-8859-7">
<p><textarea name="input" maxlength="10" rows="5" cols="100"></textarea></p>
<p><button>Submit</button></p>
</form>
encode.php:
<head>
<meta charset="ISO-8859-7"><!-- Useless, Even if is specified the ISO-8859-1 where the "¥" exist, the form sended a reference char rather an a byte to interpret.-->
</head>
<?php
$input=$_POST["input"];
var_dump($input);
?>
结果的源代码:
string(6) "¥"
注意:我测试过更改用于存储文件的编码。
在 的index.php: 不要紧编码来存储文件,表单总是会相应地与accept-charset=""
属性或与<meta charset="">
标签如果没有指定accept-charset=""
被发送。
并与encode.php: 该字符串从不编码的文件。可以工作和表示,但用于存储文件的编码与此无关。
为什么不使用UTF-8? – CuriousMind
我使用UTF-8,但我想知道这个问题。 – nEAnnam
'Content-Type'头部是否可以发送冲突字符集? – cmbuckley