Writing the contents of an array to another file?
I'm attempting to test out the PayPal IPN, so I want to set-up a script to write all the contents of the $_GET
array to a file, so I can see if what is requested is as I assume.
However, I'm having trouble configuring the file to actually display the contents of the array as though it were being dumped.
For example:
$string = $_GET;
$fp = fopen("paypal_req.txt", "w");
fwrite($fp, $strin开发者_如何学JAVAg);
fclose($fp);
Simply echo's the value of $_GET
into the file paypal_req.txt
, which of course is Array
.
How could I have the contents of the array $_GET
dumped into paypal_req.txt
as though I were using var_dump()
?
Any help would be greatly appreciated!
$string = print_r($_GET, true);
If you want a similar output to var_dump(), you can use the var_export() function:
$string = var_export($_GET, true);
The var_export($_GET, true)
suggestion is the best, but you could use var_dump by capturing its output with output buffering.
<?php
ob_start();
var_dump($_GET);
$dump = ob_get_clean();
?>
精彩评论