Home  >  Article  >  Backend Development  >  Detailed explanation of deleting newlines when reading files line by line in PHP

Detailed explanation of deleting newlines when reading files line by line in PHP

php中世界最好的语言
php中世界最好的语言Original
2018-05-21 11:09:211856browse

This time I will bring you a detailed explanation of the operation of deleting newline characters when reading files in PHP. Precautions for deleting newline characters when reading files in PHP. What are they? The following is a practical case. Let’s take a look. Example, PHP reads the file line by line and removes the newline character "\n":

//第一种
$content=str_replace("\n","",$content);echo $content;
//或者:
$content=str_replace(array("\n","\r"),"",$content);
//第二种:
$content=preg_replace("/\s/","",$content);
echo $content;
//第三种:
$content=trim($content);

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to php Chinese Other related articles online!

Recommended reading:

array_combine() array merge function usage case details


php array search function usage summary


in_array() Find whether an array value exists Case sharing

The above is the detailed content of Detailed explanation of deleting newlines when reading files line by line 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