Home  >  Article  >  Backend Development  >  How to solve the problem of carriage return and line feed conversion in php

How to solve the problem of carriage return and line feed conversion in php

coldplay.xixi
coldplay.xixiOriginal
2020-09-30 09:29:544762browse

php method to solve carriage return and line feed conversion: 1. Use the file function, the code is [$list = file($intstr)]; 2. Use the replace function, the code is [ereg_replace("\r\ n", "", $value);].

How to solve the problem of carriage return and line feed conversion in php

php method to solve carriage return and line feed conversion:

Method 1: nl2br (PHP 4, PHP 5 )

nl2br — Inserts HTML line breaks before all newlines in a string

Method 2: You can use the file() function, the example is as follows

function fmtfilenl($intstr)
{
 $list = file($intstr);
 foreach($list as $row) {
    $outstr=$outstr.$row.'
';
 }
 return $outstr;
}

Method 3:

$a = preg_replace("/[\r\n]+/", ',', $a);或$a = join(',', split("[\r\n]+", $a));

Method 4:

ereg_replace("\r\n", "", $value);

The last one to know , PHP code

str_replace("\n", '', str_replace("\r\n", "\n", $a));
or
str_replace(PHP_EOL, "\n", $a )

If you want to learn more about programming, please pay attention to the php training column!

The above is the detailed content of How to solve the problem of carriage return and line feed conversion in php. For more information, please follow other related articles on 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