如何将var_dump的结果捕获到字符串? [英] How can I capture the result of var_dump to a string?
本文介绍了如何将var_dump的结果捕获到字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想捕获 var_dump
字符串.
I'd like to capture the output of var_dump
to a string.
PHP文档说;
与将结果直接输出到浏览器的任何内容一样, output-control函数可用于捕获此函数的输出,并将其保存在字符串中(例如).
As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example).
这可能是一个如何工作的例子?
What would be an example of how that might work?
print_r()
的可能性不大,因为它不会给我所需的信息.
print_r()
isn't a valid possibility, because it's not going to give me the information that I need.
推荐答案
使用输出缓冲:
<?php
ob_start();
var_dump($someVar);
$result = ob_get_clean();
?>
这篇关于如何将var_dump的结果捕获到字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文