php – 使用文件处理函数将逗号放在txt文件中
发布时间:2020-12-13 21:48:12 所属栏目:PHP教程 来源:网络整理
导读:这是我的代码 ?php $filename = 'names.txt'; $file = fopen($filename,'w'); fwrite($file,implode(",",$filename));? 我的names.txt文件数据是这样的 saadAlexAshmilShumailFredrik 除了最后一个名字之外,我希望在每个名字后加上一个qoma. .但是我收到了“
这是我的代码
<?php $filename = 'names.txt'; $file = fopen($filename,'w'); fwrite($file,implode(",",$filename)); ?> 我的names.txt文件数据是这样的 saad Alex Ashmil Shumail Fredrik 除了最后一个名字之外,我希望在每个名字后加上一个qoma. .但是我收到了“错误的论点传递给内爆功能”的错误.告诉我现在该怎么办? 预期的产出应该是 萨德,亚历克斯,阿什米尔,舒梅尔 解决方法
也试试这个.
它工作…… <?php $file = 'names.txt'; $array = file($file); // Creates an array of each line $array = array_slice($array,-1); // Pops the last element of an array $string = implode(',',$array); // Implode file_put_contents($file,str_replace("n","",$string)); ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |