PHP清除字符串中空白正则表达式
先利用trim系列函数来删除左右空格
代码如下 | 复制代码 |
trim 去除一个字符串两端空格, echo trim(" 空格 ")." ?> |
删除所有空格不能使用php trim()函数,因类他也只能是去除两边空闲
代码如下 | 复制代码 |
|
上面只能删除是一些常见的空格了,下面分享一个更具体的。
代码如下 | 复制代码 |
$str = " This line containstliberal rn use of whitespace.nn"; // First remove the leading/trailing whitespace // Now remove any doubled-up whitespace // Finally, replace any non-space whitespace, with a space // Echo out: 'This line contains liberal use of whitespace.' {$str} Copy after login |
中间就是利用了替换连续空格与左右空格之后再利用preg_replace替换去除重复的,然后再用另一个正则表达式[nrt]来查找任何残余的换行符(n), 回车(r), 或制表符(t) 即可。
永久链接:
转载随意!带上文章地址吧。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

