PHP中替换换行符方法总结
php中替换换行符的方法总结,php 有三种方法来解决。
1、使用str_replace 来替换换行
$str=str_replace(array("\r\n","\r","\n"),"",$str);
2、使用正则替换
$str=preg_replace('//s*/','',$str);
3、使用php定义好的变量 (建议使用)
$str=str_replace(PHP_EOL,'',$str);
转为前台可显示的换行, nl2br 的方向函数参考php手册
$str="a b e f c"; echo nl2br($str);
输出html代码如下:
a
b
e
f
c
您可能感兴趣的文章
- php利用正则过滤各种标签,空格,换行符的代码
- php如何将html中的br换行符转换为文本输入中的换行符
- PHP压缩html网页代码(清除空格,换行符,制表符,注释标记)
- css控制英文、中文强制换行与不换行的代码
- php字符串替换函数str_replace速度比preg_replace快
- PHP 只替换一次,控制替换次数
- PHP压缩html网页代码减小网络数据传输量,清除空格,制表符,注释标记
- 在php中分别使用curl的post提交数据的方法和get获取网页数据的方法总结

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)