Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see full content of long strings with var_dump() in PHP

I have an array with some strings like

$array = array("string1","string2","string3"); 

But those strings are very long, with a length of 2000+ sometimes. So when I do

echo "<pre>"; var_dump($array); echo "</pre>"; 

It shows me something like

string 'zzzzzzzzzzzzzzzzz '... (length = 994) string 'yyyyyyyyyyyyyyyyy '... (length = 1287) string 'xxxxxxxxxxxxxxxxx '... (length = 1718) 

Instead of the full string. How can I see the whole content of my array? And for those who will ask, it contains HTML tags, so that's why I don't write echo $array[string];

like image 749
Carlos2W Avatar asked Dec 17 '15 19:12

Carlos2W


People also ask

Why Var_dump () is preferable over Print_r ()?

It's too simple. The var_dump() function displays structured information about variables/expressions including its type and value. Whereas The print_r() displays information about a variable in a way that's readable by humans. Example: Say we have got the following array and we want to display its contents.

What is Var_dump ()?

The var_dump() function is used to dump information about a variable. This function displays structured information such as type and value of the given variable. Arrays and objects are explored recursively with values indented to show structure. This function is also effective with expressions.

What is the difference between Var_dump () and Print_r ()?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.


1 Answers

You are using xdebug, which overloads the default var_dump() to give you prettier and more configurable output. By default, it also limits how much information is displayed at one time. To get more output, you should change some settings.

Add this to the top of your script:

ini_set("xdebug.var_display_max_children", '-1'); ini_set("xdebug.var_display_max_data", '-1'); ini_set("xdebug.var_display_max_depth", '-1'); 

From 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.

like image 95
elixenide Avatar answered Sep 22 '22 22:09

elixenide