我有一个输入字段(自动填充),格式名称为 <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a27332f272b23260a2225393e64292527" rel="noreferrer noopener nofollow">[email protected]</a>>
。我给出了表格 enctype="application/x-www-form-urlencoded"
,但是当我在 PHP 中检索它时,它只显示名称。请帮我找回电子邮件。
我的 HTML 表单:
<form action="{$path_site}{$index_file}" method="POST" enctype="application/x-www-form-urlencoded">
<table>
<tr>
<td>Your Name</td>
<td><input type="text" name="sender_name" size="37" /></td>
</tr>
<tr>
<td>To</td>
<td><input type="text" name="reciever_name" size="37" id="inputString" onkeyup="lookup(this.value)" onblur="fill()" /></td>
</tr>
</table>
</form>
和 PHP 代码:
echo $msg_sender_name = $info[reciever_name];
最佳答案
从评论中提取信息,您说:
if the text is like "myName<[email protected]>",
info['reciever_name']
displays only "myName"
我想说,您的问题与显示结果有关,与表单无关。
您可能会将收到的字符串显示为 HTML,其中字符“<”和“>”是特殊的。
而不是
echo $info['reciever_name'];
您应该使用htmlspecialchars功能:
echo htmlspecialchars($info['reciever_name'], ENT_QUOTES);
这是 PHP(以及许多其他语言)中最常见的错误。
您应该转义您显示的所有文本,尤其是当它来自不受信任的来源时 - 并且用户提供的每个值都是不受信任的>.
如果无法转义输出,您的用户就会面临安全风险 - 您可能需要阅读 Cross-site-scripting在维基百科上。
关于php - 以 HTML 形式发送特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7384703/