我将表单输入保存为.txt文件。我已经完成了这个部分:
twinx(ax=ax1)
由于我有很多$ _POST变量,我希望在值旁边有变量的名称。所以最佳输出看起来像这样:
$myFile = "files/".$fileid. '.txt';
$fh = fopen($myFile, 'a');
$comma_delmited_list = implode("\t", $_POST) . "\n";
fwrite($fh, $comma_delmited_list);
fclose($fh);
等等。
这可能吗?
答案 0 :(得分:2)
更新
$arr = array();
foreach ($_POST as $k => $v) {
$arr[] = $k . ' = ' . $v;
}
$comma_delmited_list = implode(" ", $arr) . "\n";
逃避安全恢复:
$arr = array();
foreach ($_POST as $k => $v) {
$arr[] = preg_replace('~\t~', ' ', preg_replace('~=~', '', $k) . ' = ' . $v);
}
$comma_delmited_list = implode("\t", $arr) . "\n";
转义安全恢复+“$ _POST数组”:
$arr = array();
foreach ($_POST as $k => $vArray) {
if (!is_array($vArray)) {
$vArray = array($vArray);
}
$i = 0;
foreach ($vArray as $v) {
$arr[] = preg_replace('~\t~', ' ', preg_replace('~=~', '', $k . (count($vArray) > 0 ? $i++ : '')) . ' = ' . (string)$v);
}
}
$comma_delmited_list = implode("\t", $arr) . "\n";
这会解决您的问题吗?