【问题标题】:Splitting txt file to new lines将txt文件拆分为新行
【发布时间】:2019-01-20 11:34:43
【问题描述】:

我有一个大的 txt 文件是这样的: "你好,你好吗878SAZ我很好谢谢你878SAZ祝你有美好的一天"

每当我看到“878SAZ”时,我都想将此文件拆分为新行并将其另存为 txt.. 我尝试了几件事,但我无法做到这一点,该怎么办?

$txt_file = file_get_contents('C:/files/file.txt');
$rows = explode("878SAZ", $txt_file);

array_shift($rows);
foreach($rows as $row)
{
}
file_put_contents("C:/files/file.txt, $rows)";

【问题讨论】:

  • 你应该表现出你的努力。展示你尝试过的东西,即使它不起作用。

标签: php file split


【解决方案1】:

您可以尝试将字符串 '878SAZ' 替换为“\n”,即换行符

$input = file_get_contents(YOUR_FILE_PATH);
$text = str_replace('878SAZ', "\n", $input);
file_put_contents(WRITE_FILE_PATH, $text);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2017-04-08
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多