I have a script that is writing variables to a text file, I am using fwrite(). here is the script:
<?php
error_reporting(E_ALL ^ E_NOTICE);
$filename = 'Report.txt';
$batch_id = $_GET['batch_id'];
$status = $_GET['status'];
$phone_number = $_GET['phone_number'];
//check to see if I could open the report.txt
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// I am trying to write each variables to the text file
if (fwrite($handle, $phone_number) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($phone_number) to file ($filename)";
fclose($handle);
?>
I have 2 problems here:
1.As I receive the report by Batch_ID I want to name each report text file with a prefix using the batch_ID for example :5626_Report.txt
2.I want to pass more than one variable to the function fwrite(), I want to write the $status next to each $phone_number.
Try fprintf.
It’s analogue to the regular printf of C, however you need to pass a handle to.
As an example:
Alternatively, you can make use of PHPs inline stringing and use:
To get to your exact problem:
That should help.