hello!
i've got this; print_r($_POST);
which works fine.
but how can i turn the data into a variable with linebreaks so i can just go
echo $postedData;
i just want to include the posted data into an email script which can only accept variables or strings...
many thanks, Dan.
$_POST is an array, so loop over it.
i tried that but there's only one of each variable and i didn't get anywhere.
are you saying that; $_POST[1] should print the 2nd field and value in the array? surname => jones
?
No. $POST is an associative array. If you want to print the element with the key of 'surname', then print $POST['surname']. If you want to loop over the array use a foreach loop.
thanks!
tried again with;
foreach($_POST as $item){ $postedData .="". $item."\n"; } echo $postedData;
which prints out the field value, but i'd like to print out the fieldname to if possible?
D.
$postedData = ''; foreach($_POST as $key => $item){ $postedData .= $key . ': ' . $item . "\n"; } echo $postedData;
ahhh!
many thanks laserlight!
Don't forget to mark this thread resolved (if it is) using the option on the Thread Tools menu above.
Not that print_r() is necessarily a good way to do what you want, but I do want to point out that if you set it's optional 2nd parameter to true, it will return the string instead of outputting it:
$var = print_r($_POST, true);