如何在 PHP 中的变量中用空格替换制表符? [英] How do I replace tabs with spaces within variables in PHP?

查看:20
本文介绍了如何在 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));

这篇关于如何在 PHP 中的变量中用空格替换制表符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆