function writePlayerInfo($playerFName, $playerSName, $phone, $email){
$data = array();
array_push($data, $playerFName, $playerSName, $phone, $email);
$handleName = fopen("data/names.csv","w");
foreach ($data as $line)
{
fputcsv($handleName,explode(',',$line));
}
fclose($handleName);
$datas = array();
}
if (isset($_POST['submit'])) {
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
writePlayerInfo($fname, $lname, $phone, $email);
header('Location: createplayer.php');
}
嗨,大家好,谢谢
我正在尝试写入一个csv文件,我已经使其正常工作,我当前的代码在csv文件中显示信息,如下所示:
Dave
Smith
01210112345
Email@stack.com
但是我希望它写入这样的文件
Dave Smith 01210112345 Email@stack.com
然后我想要它,因此下次我调用它在下面的行中编写的函数时,有什么主意吗?
答案 0 :(得分:0)
带有delimiter =“ \ t”的fputcsv
function writePlayerInfo($playerFName, $playerSName, $phone, $email){
$data = array();
array_push($data, $playerFName, $playerSName, $phone, $email);
$handleName = fopen("data/names.csv","w");
fputcsv($handleName, $data, "\t");
fclose($handleName);
$datas = array();
}