php - 以 HTML 形式发送特殊字符

标签 php html forms enctype

我有一个输入字段(自动填充),格式名称为 <<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/

相关文章:

php - PHP中的函数重载

php - 如何通过 shell_exec 将 PHP 变量值传递给 Python

php - MySQL 读取/修改/写入字段的替代方案

html - 最大高度的奇怪填充

html - 如何用jquery mobile实现多列表?

javascript - 将文本区域内容转储到 JS Alert 中?

php - fatal error : Class 'Swift_smtpTransport' not found in

html - youtube 使用对象标签全屏嵌入视频

html - 在 IE8 中自定义下拉列表高度

javascript - Angular 2 需要表单组中的两项之一