i have a small function to write contents
function write($data)
{
file_put_contents("filename.txt",$data,FILE_APPEND);
}
it works good except some where when i do the following
write( var_dump($someObject) );
this gives an error message of
illegal character.
I see the this error message through an alert box in browser the php gets call through an ajax call. Any help in debugging this would be appreciated thanks.
var_dumpwill not work like that because it outputs directly instead of returning the output. If you want to capture the output in order to write it somewhere else you have to use output buffering:Alternatively,
var_exportis also something that would work as long as you remember to pass intruefor the second parameter: