I think instead
ob_get_flush()
Do you want to
$var = ob_get_clean(); file_put_contents("$server.txt", $var );
To do all this, you will need to do it
while ($row = mysql_fetch_assoc($result)) { ob_start(); var_dump($row); file_put_contents("$server.txt",ob_get_clean()); }
http://php.net/manual/en/function.ob-get-clean.php
Get the current contents of the buffer and delete the current output buffer ... Returns the contents of the output buffer and the end of output buffering. If output buffering is not active, FALSE is returned.
-Note- the end output buffering That's why we need to restart its ob_start() on each iteration of the loop.
For ob_get_flush()
The output buffer should be started using ob_start () with the PHP_OUTPUT_HANDLER_FLUSHABLE flag. Otherwise, ob_get_flush () will not work.
This suggests that this is not the best approach to your goal. As an alternative method, you can use this funciton
function getVarType( $var, $escapeHtml = true ){ $strArg = 'unknown'; switch ( gettype( $var ) ){ case 'boolean': return ( $var ? 'true' : 'false' ); case 'integer': return intval( $var ); case 'double': return floatval( $var ); case 'string': if( $escapeHtml ){ $var = htmlentities( $var, ENT_NOQUOTES, 'UTF-8', false); } return "'".$var."'"; case 'resource': return 'Resource id #'.intval( $var ); case 'NULL': return 'NULL'; case 'array': return "Array"; case 'object': return 'Object('.get_class( $var ).')'; case 'unknown type': default: return'UNKNOWN TYPE'; } } $row = array_map( 'getVarType', $row );
However, I think in PHP 7 they canceled the options for an array map. This is from the exception / error handling class that I just wrote, you can modify it to match var_dump more precisely if you want. It is currently configured to match the printout of the exception stack trace.
By the way, if you really want the killer debugger class, you can use it from my framework
https://github.com/ArtisticPhoenix/Evo/blob/master/EVO/Debug.php
With some slight modification, it may suit your needs (maybe outsmart a little)
This is what it infers
$G = ['one'=>1, 'two' => 2, 3=>['foo', 'bar']]; EVO_Debug::dump( $G ); ==================================== EVO_DEBUG::DUMP ===================================== Output from FILE[ C:\UniServerZ\www\Evo\EVO\bootstrap.php ] on LINE[ 72 ] ------------------------------------------------------------------------------------------ array(3){ ["one"] => int(1), ["two"] => int(2), [3] => array(2){ [0] => string(3) "foo", [1] => string(3) "bar", }, } ==========================================================================================
Although you want to use
EVO_Debug::export( $G );
It can also output private properties and class constants. I send the link only because it is not trivial to deal with all possible types of variables, and here it does not help that PHP is a language without typing.