PHP 中的 print_r() 和 mail() 输出不同的内容,为什么?

发布于 2024-09-06 05:29:38 字数 267 浏览 3 评论 0原文

我有一个 html 表单,访问者可以在其中填写一些信息并将其以电子邮件的形式发送给我。它像这样发送:

$body = print_r($_POST, true);

mail ($to, $subject, $body, $headers);

当他们写 abc'def 时,我得到 abc\'def

这个额外的 \ 是什么?我怎样才能预防它?

I have a html form where visitors can fill and send me some information, as an e-mail. It sends like this:

$body = print_r($_POST, true);

mail ($to, $subject, $body, $headers);

When they write abc'def I get abc\'def

What is this additional \? How I can prevent it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年慕年 2024-09-13 05:29:38

因为神奇的引号。请参阅此处

它们不会输出不同的内容 - $_POST 超全局已经有了反斜杠。

Because of magic quotes. See here.

They don't output something different – the $_POST superglobal already has the backslash.

橙幽之幻 2024-09-13 05:29:38

这是最有可能的,因为您打开了魔法引号,但是您可以,像这样进行:

if (get_magic_quotes_gpc())
{
   $new_text = stripslashes($text);
}

现在 $new_text 应该正常输出。

That's most possible because you have magic quotes turned on, you can however, go about like this:

if (get_magic_quotes_gpc())
{
   $new_text = stripslashes($text);
}

Now $new_text should output normally.

南城旧梦 2024-09-13 05:29:38

反斜杠是一个转义字符 - 它让解析器知道您不想以 PHP 理解的正常方式使用单引号。如果您想在输出中删除它们,请使用 stripslashes 方法。

字符串 stripslashes ( string $str )

The backslash is an escape character - it lets the parser know that you don't want to use the single-quote in the normal way that PHP understands them. If you want to remove them in your output, use the stripslashes method.

string stripslashes ( string $str )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文