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

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

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Seeing the Whole Story: Displaying Long Strings in PHP

When debugging a PHP script containing massive strings, var_dump() often feels like looking through frosted glass. You get the type, the length, and a truncated preview of the content, but the actual data remains hidden behind ellipses. This is particularly frustrating when those strings contain complex HTML structures or specific binary patterns that you need to inspect character-by-character. The default behavior truncates output to prevent overwhelming the browser or terminal, showing something like string 'zzzz... ' (length = 994) instead of the raw content.

To see the full content without manually copying and pasting from a file system, you must explicitly instruct PHP to disable truncation. The core mechanism lies in the var_dump() function's internal logic regarding output formatting. By default, if a string exceeds a certain length (historically 768 characters in older versions, though often configurable via configuration), it gets cut off for readability.

The most direct solution is to use the second argument of var_dump(). This function signature accepts an optional boolean flag that controls whether truncation should occur. By passing false as the second argument, you force PHP to output the entire string content regardless of its length.

Here is how you modify your debugging code:

$array = ["string1", "string2", "string3"];

// Disable truncation for full visibility
var_dump($array, false);

In this example, false tells var_dump() to treat the output buffer as unlimited regarding string length. If you are debugging a single variable directly, you can pass false immediately after the variable name. This approach works universally across PHP versions that support the function signature variation introduced in version 5.4.0 and remains stable in modern PHP 8.x.

However, there is a significant trade-off to consider: performance and output size. When you disable truncation on strings exceeding 2,000 characters, the resulting HTML or text dump becomes massive. If you are running this inside an echo block wrapping <pre> tags in a browser, the page will likely hang or crash because the response body exceeds memory limits or causes the server to timeout before sending the full payload.

In production environments or when debugging via CLI, this is manageable. In a web context, the safest approach is often to redirect the output to a log file rather than printing it directly to the screen. You can use var_dump() with error handling or write the string content to a temporary file using file_put_contents().

Alternatively, if you need to inspect HTML specifically and want to avoid raw var_dump noise, consider using print_r() combined with custom formatting or leveraging tools like xdebug for line-by-line inspection. Xdebug's stack trace viewer often renders variables in a way that allows toggling between collapsed and expanded states without the browser choking on massive output blocks.

If your strings are part of a larger array where only specific elements are problematic, you can target them individually:

foreach ($array as $key => $value) {
    var_dump($key, $value, false);
}

This granularity ensures that if the first string is huge, it doesn't break the rendering of subsequent smaller strings in a single dump. It also makes it easier to correlate the length with specific data structures.

Remember that while var_dump() is excellent for quick inspection during development, relying on it for large datasets in production logging can bloat log files and degrade system performance. Always weigh the need for full visibility against the cost of generating terabytes of debug output. When dealing with sensitive HTML or large payloads, ensure you are not inadvertently exposing internal data structures that could aid attackers if the logs become accessible to unauthorized parties.

Our network