Home >Backend Development >PHP Tutorial >A brief analysis of the problem that \r\n cannot be used to wrap lines when writing txt files using php fwrite

A brief analysis of the problem that \r\n cannot be used to wrap lines when writing txt files using php fwrite

高洛峰
高洛峰Original
2017-02-03 15:17:141856browse

I encountered a problem today that when using fwrite to write a txt file, I cannot use rn to wrap the line.
I tried for a long time but couldn’t find a solution!
Suddenly I thought of something that I had seen in a book before and then I still used this. Dongdong has solved it!
Write it now to prevent forgetting in the future and hope it can help friends who need help!
Look at the code directly:

<?php
$stream = fopen("robots.txt", "w+");
fwrite($stream, "你换行了吗\r\n我已经换行了!");
?>

More analysis of how php fwrite writes txt files When using \r\n, you cannot wrap the line. For related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn