如何在 PHP 中的变量中用空格替换制表符?

2021-12-25 00:00:00 replace tabs spaces php

$data 包含制表符、前导空格和多个空格.我希望用空格替换所有选项卡.多个空格一个空格,并去除前导空格.

$data contains tabs, leading spaces and multiple spaces. I wish to replace all tabs with a space. Multiple spaces with one single space, and remove leading spaces.

事实上,会改变这个输入数据的东西:

In fact somthing that would turn this input data:

[    asdf asdf     asdf           asdf   ] 

进入输出数据:

[asdf asdf asdf asdf]

我该怎么做?

推荐答案

$data = trim(preg_replace('/s+/g', '', $data));

相关文章