先利用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}"; |
中间就是利用了替换连续空格与左右空格之后再利用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

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment