bschultz Posted May 31, 2010 Share Posted May 31, 2010 I'm trying to write some variable values to a separate file. That separate file will be used in an include on a third file. File1 is a simple html form File2 processes that form, and writes the data to File3 File4 reads the variables from File3 and compares them to a database...and prints out the results. File1, File3 and File4 all work fine. File2 (which uses fwrite) isn't writing the variable name to the file. Here's the code: <?php $myFile = "testFile.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = " <?php \n\n $your_page_title = \"$_POST[your_page_title]\";\n $your_number_color = \"$_POST[your_number_color]\";\n $your_position_color = \"$_POST[your_position_color]\";\n $your_name_size = \"$_POST[your_name_size]px\";\n $your_stats_color = \"$_POST[your_stats_color]\";\n ?> "; fwrite($fh, $stringData); fclose($fh); ?> The above code writes this to the file = "My Title"; = "green"; = "blue"; = "14px"; = "red"; As you can see, none of the variable names are written to the file. It should read this $your_page_title = "My Title"; $your_number_color = "green"; $your_position_color = "blue"; $your_name_size = "14px"; $your_stats_color = "red"; How can I get the variable names to be written to the file? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/203454-fwrite-question/ Share on other sites More sharing options...
riwan Posted May 31, 2010 Share Posted May 31, 2010 try this <?php $myFile = "testFile.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "<?php \n\n \$your_page_title = \"$_POST[your_page_title]\";\n \$your_number_color = \"$_POST[your_number_color]\";\n \$your_position_color = \"$_POST[your_position_color]\";\n \$your_name_size = \"$_POST[your_name_size]px\";\n \$your_stats_color = \"$_POST[your_stats_color]\";\n ?> "; fwrite($fh, $stringData); fclose($fh); ?> Quote Link to comment https://forums.phpfreaks.com/topic/203454-fwrite-question/#findComment-1065854 Share on other sites More sharing options...
bschultz Posted May 31, 2010 Author Share Posted May 31, 2010 riwan, that worked great! Thank you. What did adding those extra slashes do? I always like to learn! Quote Link to comment https://forums.phpfreaks.com/topic/203454-fwrite-question/#findComment-1065860 Share on other sites More sharing options...
jcbones Posted May 31, 2010 Share Posted May 31, 2010 Told PHP parser to ignore the next character. Quote Link to comment https://forums.phpfreaks.com/topic/203454-fwrite-question/#findComment-1065866 Share on other sites More sharing options...
bschultz Posted May 31, 2010 Author Share Posted May 31, 2010 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/203454-fwrite-question/#findComment-1065868 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.