如何在 PHP 中使用 var_dump() 查看长字符串的完整内容
How to see full content of long strings with var_dump() in PHP
我有一个包含一些字符串的数组,例如
$array = array("string1","string2","string3");
但是那些字符串很长,有时长度超过2000。所以当我做
echo "<pre>";
var_dump($array);
echo "</pre>";
它向我展示了类似
的内容
string 'zzzzzzzzzzzzzzzzz '... (length = 994)
string 'yyyyyyyyyyyyyyyyy '... (length = 1287)
string 'xxxxxxxxxxxxxxxxx '... (length = 1718)
而不是完整的字符串。我怎样才能看到数组的全部内容?对于那些会问的人,它包含 HTML 标签,所以这就是为什么我不写 echo $array[string];
这样的东西也会在值中显示任何 html 标签:
foreach($array as $key=>$value) {
echo($key.':<br /><pre>'.htmlspecialchars($value).'<pre><hr>');
}
您正在使用 xdebug,它会重载默认 var_dump()
以提供更漂亮和更可配置的输出。默认情况下,它还会限制一次显示多少信息。要获得更多输出,您应该更改一些设置。
将此添加到脚本的顶部:
ini_set("xdebug.var_display_max_children", '-1');
ini_set("xdebug.var_display_max_data", '-1');
ini_set("xdebug.var_display_max_depth", '-1');
来自the docs:
xdebug.var_display_max_children
Type: integer, Default value: 128
Controls the amount of array children and object's properties are shown when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.
To disable any limitation, use -1 as value.
This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.
xdebug.var_display_max_data
Type: integer, Default value: 512
Controls the maximum string length that is shown when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.
To disable any limitation, use -1 as value.
This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.
xdebug.var_display_max_depth
Type: integer, Default value: 3
Controls how many nested levels of array elements and object properties are when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.
The maximum value you can select is 1023. You can also use -1 as value to select this maximum number.
This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.
有时,在处理长字符串时,使用 var_dump
可能会非常乏味。
您可以使用终端,而不是在浏览器上输出结果。
另一种解决方案是使用 file_put_contents
或类似的方法将结果输出到文本文件中。然后打开文件查看结果。
我有一个包含一些字符串的数组,例如
$array = array("string1","string2","string3");
但是那些字符串很长,有时长度超过2000。所以当我做
echo "<pre>";
var_dump($array);
echo "</pre>";
它向我展示了类似
的内容string 'zzzzzzzzzzzzzzzzz '... (length = 994)
string 'yyyyyyyyyyyyyyyyy '... (length = 1287)
string 'xxxxxxxxxxxxxxxxx '... (length = 1718)
而不是完整的字符串。我怎样才能看到数组的全部内容?对于那些会问的人,它包含 HTML 标签,所以这就是为什么我不写 echo $array[string];
这样的东西也会在值中显示任何 html 标签:
foreach($array as $key=>$value) {
echo($key.':<br /><pre>'.htmlspecialchars($value).'<pre><hr>');
}
您正在使用 xdebug,它会重载默认 var_dump()
以提供更漂亮和更可配置的输出。默认情况下,它还会限制一次显示多少信息。要获得更多输出,您应该更改一些设置。
将此添加到脚本的顶部:
ini_set("xdebug.var_display_max_children", '-1');
ini_set("xdebug.var_display_max_data", '-1');
ini_set("xdebug.var_display_max_depth", '-1');
来自the docs:
xdebug.var_display_max_children
Type: integer, Default value: 128
Controls the amount of array children and object's properties are shown when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.
To disable any limitation, use -1 as value.
This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.
xdebug.var_display_max_data
Type: integer, Default value: 512
Controls the maximum string length that is shown when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.
To disable any limitation, use -1 as value.
This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.
xdebug.var_display_max_depth
Type: integer, Default value: 3
Controls how many nested levels of array elements and object properties are when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.
The maximum value you can select is 1023. You can also use -1 as value to select this maximum number.
This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.
有时,在处理长字符串时,使用 var_dump
可能会非常乏味。
您可以使用终端,而不是在浏览器上输出结果。
另一种解决方案是使用 file_put_contents
或类似的方法将结果输出到文本文件中。然后打开文件查看结果。