相当于通过电子邮件发送数据的 var_dump

发布于 2024-12-19 07:53:02 字数 96 浏览 5 评论 0原文

我一直在寻找一个 php 库,它允许我通过电子邮件发送变量的格式化数据(如 krumo)。

这是因为我创建了一个错误处理程序,用于发送包含生产环境数据的电子邮件。

I've been looking for a php library that allows me to send formatted data (like krumo) for variables via email.

This is because I've created an error handler that sends an email with the data on production environment.

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

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

发布评论

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

评论(4

赴月观长安 2024-12-26 07:53:02

您可以 json_encode()serialize() 如果您希望数据是机器可读的。

如果您希望它易于人类阅读,您可以将第二个参数 TRUE 提供给 print_r() 以字符串形式返回数据,或使用 输出缓冲以捕获var_dump()的输出成字符串。

例如

// For machine-readable results
$dataStr = json_encode($data);
// ...or...
$dataStr = serialize($data);

// For human-readable results
ob_start();
var_dump($data);
$dataStr = ob_get_clean();
// ...or...
$dataStr = print_r($data, TRUE);

You could json_encode() or serialize() the data if you want it to be machine readable.

If you want it to be human readable, you can either supply the second argument TRUE to print_r() to return the data as a string, or use output buffering to catch the output of var_dump() into a string.

e.g.

// For machine-readable results
$dataStr = json_encode($data);
// ...or...
$dataStr = serialize($data);

// For human-readable results
ob_start();
var_dump($data);
$dataStr = ob_get_clean();
// ...or...
$dataStr = print_r($data, TRUE);
°如果伤别离去 2024-12-26 07:53:02
mail('[email protected]', 'dump', print_r($obj, true));

将发送 $obj 内容的人类可读版本。如果您需要类型/大小信息,可以使用 var_dump,但需要使用 ob 函数来捕获其输出,因为它没有“返回而不是输出”选项。

mail('[email protected]', 'dump', print_r($obj, true));

would send human-readable versions of $obj's contents. If you need type/sizing information, you can use var_dump, but will need to use the ob functions to capture its output, as it doesn't have a 'return instead of outputting' option.

牵强ㄟ 2024-12-26 07:53:02

我将使用 json_encode() 并将变量作为 JSON 字符串在电子邮件中发送。

I would use json_encode() and send variables as a JSON string in the email.

噩梦成真你也成魔 2024-12-26 07:53:02

另一种方式可以将其作为 HTML 发送
例如

$sent = "<pre>".var_dump($data,true)."</pre>"; 

但请确保将电子邮件内容的标题设置为

$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";

another way you can send it as HTML
For example

$sent = "<pre>".var_dump($data,true)."</pre>"; 

But make sure to set the headers of the email content to

$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文