我将字段输入传递给.csv表单,但我想知道是否可以将变量名称与值打印在一起?打印CVS输入的变量名称
这里是我如何打印到将该.cvs:
PHP
<?php
$csvdata = $firstName . ", " . $lastName . ", " . $homeAddress . ", " . $homeAddressTwo . ", " . $city . ", " . $province . ", " . $postalCode . ", " . $homePhone . ", " . $personalEmail . ", " . $confirmEmail . ", " . $oectaNumber . ", " . $memberStatus . ", " . $teacherTraining . ", " . $teachingYears . "," . $employmentHistoryValues;
$fp = fopen("formdata.csv", "a");
if($fp)
{
fwrite($fp, $csvdata . "\n");
fclose($fp);
}
?>
这里就是我想要它看起来像:
Array ([0] => WLU [1] => Math [2] => 2016)
下面是我正在处理这些变体:
$educationHistoryValues = "";
foreach(print_r($_POST["educationHistory"]) as $educationValue)
{
$educationHistoryValues .= $educationValue;
}
输入数据:
<div id="educationHistory" name="educationHistory[]">
<input type="text" class="three-lines" name="educationHistory[]" id="educationInstitution_1" placeholder="Institution" onblur="this.placeholder='Institution'" onfocus="this.placeholder=''" onkeyup="checkPage2()" />
<input type="text" class="three-lines" name="educationHistory[]" id="degreeFromInstitution_1" placeholder="Degree/Diploma" onblur="this.placeholder='Degree/Diploma'" onfocus="this.placeholder=''" onkeyup="checkPage2()" />
<input type="date" class="three-lines" name="educationHistory[]" id="educationalDates_1" />
<input type="button" value="+" onclick="addEducation()" />
</div><!--end educationHistory Div -->
</div><!--end of education div-->
在CSV文件本身,结果是很容易破解,但是我从绘画形式有一堆的动态输入,这将产生多维数组和一些输入是文字区域,所以我想测试这个理论。
您准确预计什么输出结果? – krasipenkov
目前它仅在特定单元格中输入输入结果。当我print_r整个表单时,它给出了一个相当整洁的布局,像这样:[memberStatus] =>好,其中成员状态是变量名称,好的是用户输入。会有这样的事情吗? –
变量来自哪里?在你的例子中哪些是动态的(你对它们进行了硬编码,这对我来说意味着你知道动力学?) – nerdlyist