I'm trying to export some extracted $_POST information into a text file, however my code is only capturing the first variable and ignoring the rest. I'm saving the information to the text file in this manner:
$values = "First Name: $fName\r\n";
$values .= "Last Name: $lName\r\n";
$values .= "Address: $address\r\n";
etc.
This is the code I us开发者_Python百科e to write to the text file:
$fp = @fopen("person.data", "w") or die("Couldn't open person.data for writing!");
$numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!");
@fclose($fp);
Any ideas on why it would only save the first $values ($fName) variable but not the rest of them? It actually saves the first part of the $values string for all of them (so I see Last Name:, Address:, etc. on separate lines in the text file) but the called variables $lName and $address do not appear.
Just use
file_put_contents('person.data', $value);
See http://de.php.net/manual/en/function.file-put-contents.php
Instead of "\r\n"
you can use the constant PHP_EOL
, which will contain the correct newline character(s) for the platform you are running the script on.
I see the variables are $lName - is it a case sensitivity thing? What happens if you echo the same thing?
I figured out the issue - the problem was I wasn't naming the other pieces within a hidden form I created, like I did for the person's first name.
$values = "First Name: $fName\r\n";
$values .= "Last Name: $lName\r\n";
$values .= "Address: $address\r\n";
精彩评论