如何将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();
?>