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

查看:282
本文介绍了如何在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天全站免登陆