scott.stephan Posted June 10, 2009 Share Posted June 10, 2009 I'm getting closer! Right now, I want to export a small amount of data to a .csv: a purchase order number followed by "1", i.e. "61751,1" and I need for the file to have a unique name, preferrably something like ponum_export, i.e. 61751_export. So, I managed to get the file to write and name if I provided static data. The problem arises because I have my po_num stored in a variable. Here's the code I have now: //Output to a .csv: "po_num,1" to trip the validate flag in SAGE $list = array ( '$curr_po_num,1' ); //Give it a unique name to avoid possible conflicts if Batch is delayed $fp = fopen('$curr_po_num_validation.csv', 'w'); foreach ($list as $line) { fputcsv($fp, split(',', $line)); } fclose($fp); The problem is that I get a file named "$curr_po_num_validation.csv" and the file contains "$curr_po_num,1". Meaning that instead of the value of $curr_po_num, I get "$_curr_po_num" There must be a simple answer that I am too goofy to see. Thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/161742-solved-inserting-dynamic-values-when-outputting-to-a-file/ Share on other sites More sharing options...
RussellReal Posted June 10, 2009 Share Posted June 10, 2009 try this: <?php $ponum = '92487'; $f = fopen($ponum.'_export.csv','a'); fwrite($f,$ponum.',1'); fclose($f); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161742-solved-inserting-dynamic-values-when-outputting-to-a-file/#findComment-853383 Share on other sites More sharing options...
scott.stephan Posted June 11, 2009 Author Share Posted June 11, 2009 try this: <?php $ponum = '92487'; $f = fopen($ponum.'_export.csv','a'); fwrite($f,$ponum.',1'); fclose($f); ?> That did it! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/161742-solved-inserting-dynamic-values-when-outputting-to-a-file/#findComment-853399 Share on other sites More sharing options...
RussellReal Posted June 11, 2009 Share Posted June 11, 2009 also note, I used 'a' as the mode for the file opening, only because you might want to add more to it after or there might already be data in the file, so appent "\n" or prepend Quote Link to comment https://forums.phpfreaks.com/topic/161742-solved-inserting-dynamic-values-when-outputting-to-a-file/#findComment-853401 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.