将字符串数组写入由新行字符分隔的文本文件 [英] Writing a string array to text file separated by new line character

查看:87
本文介绍了将字符串数组写入由新行字符分隔的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP页面,它接受用户在文本区域的输入。多个字符串被接受为来自用户&将包含'\ n',我将它扫描为:

I have a PHP page which accepts input from user in a text area. Multiple strings are accepted as input from user & would contain '\n' and I am scanning it as:

$data = explode("\n", $_GET['TxtareaInput']);

每个字符串应该移动到文本文件中,并换行符分隔。这是我现在使用的代码,它用'^ M'字符分隔每个字符串:

Each string should be moved into the text file with new line character separation. This is the code I am using now and it separates each string with a '^M' character:

foreach($data as $value){
    fwrite($ourFileHandle, $value);
}

无论如何,我可以得到每个字符串后跟回车吗?

Is there anyway I can get each string followed by a carriage return?

推荐答案

试试这个:

Try this:

$data = explode("\n", $_GET['TxtareaInput']);
foreach($data as $value){
    fwrite($ourFileHandle, $value.PHP_EOL);
}

这篇关于将字符串数组写入由新行字符分隔的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆