How can I capture the result of var_dump to a string?
Use output buffering:
<?php
ob_start();
var_dump($someVar);
$result = ob_get_clean();
?>
var_dump() output in a variable
Or you could just use
$content=var_export($variable,true)
echo $content;
Reference: http://www.php.net/var_export
save var_dump into text file
You can use the output buffering functions to capture output and write it to a file.
ob_flush();
ob_start();
while ($row = mysql_fetch_assoc($result)) {
var_dump($row);
}
file_put_contents("dump.txt", ob_get_flush());
Var_dump() Displays String, echo()/print_r() Returns Nothing
When <!doctype html>
is outputted the browser reads that as an element so you need to encode the <
and >
symbols. PHP has a function already built for that, http://php.net/manual/en/function.htmlspecialchars.php.
So your code should be:
echo htmlspecialchars($showres);
which in your source will give you
<!doctype html>
How to see full content of long strings with var_dump() in PHP
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.
Related Topics
Laravel Multiple Pagination in One Page
Leverage Browser Caching for 3Rd Party Js
How to Handle Error for Duplicate Entries
How to Send Emails via Cron Job Usng PHP MySQL
What's the Best Way to Pass a PHP Variable to JavaScript
How to Efficiently Find the Closest Locations Nearby a Given Location
What Does Filter_Sanitize_String Do
PHP Hierarchical Array - Parents and Childs
Remove Exif Data from Jpg Using PHP
Get Youtube Video Id from HTML Code with PHP
What Is a Factory Design Pattern in PHP