Home > Backend Development > PHP Problem > How to remove r n in php

How to remove r n in php

藏色散人
Release: 2023-03-08 13:16:02
Original
2874 people have browsed it

How to remove r and n in php: 1. Use str_replace to replace rn newline; 2. Use regular replacement and remove newline; 3. Remove newline through "str_replace(PHP_EOL, '', $str);" .

How to remove r n in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

Three methods of PHP removing line breaks code

<?php  
     //php 不同系统的换行 
    //不同系统之间换行的实现是不一样的 
    //linux 与unix中用 /n 
    //MAC 用 /r 
    //window 为了体现与linux不同 则是 /r/n 
    //所以在不同平台上 实现方法就不一样 
    //php 有三种方法来解决 
    //1、使用str_replace 来替换换行 
    $str = str_replace(array("/r/n", "/r", "/n"), "", $str);  
    //2、使用正则替换 
    $str = preg_replace(&#39;//s*/&#39;, &#39;&#39;, $str); 
    //3、使用php定义好的变量 (建议使用) 
    $str = str_replace(PHP_EOL, &#39;&#39;, $str);  
?>
Copy after login

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to remove r n in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template