PHP - 从字符串中删除所有选项卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/14586993/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP - Remove all tabs from string
提问by monkey64
I am able to remove all single tabs from a string:
我能够从字符串中删除所有单个选项卡:
// Copying and pasting the tab directly
$txt = str_replace("    ", "", $txt); 
This only removes single tabs, but not double tabs. I then tried this, thinking that "\t" would be sufficient to find the tabs:
这只会删除单个选项卡,但不会删除双选项卡。然后我尝试了这个,认为 "\t" 足以找到标签:
$txt = preg_replace('/\t/', '', $txt);
However, it didn't work. Can anyone offer something better?
然而,它没有用。谁能提供更好的东西?
回答by Zamicol
trim(preg_replace('/\t+/', '', $string))
回答by Mr. Alien
Try using this regular expression
尝试使用这个正则表达式
$string = trim(preg_replace('/\t/g', '', $string));
This will trim out all tabs from the string ...
这将从字符串中删除所有选项卡...
回答by Amani Ben Azzouz
this will remove all tabs in your variable $string
这将删除变量 $string 中的所有选项卡
preg_replace('/\s+/', '', $string);
回答by Mirko Pagliai
trim(preg_replace('/[\t|\s{2,}]/', '', $result))
Removes all tabs, including tabs created with multiple spaces
删除所有选项卡,包括使用多个空格创建的选项卡
回答by jcobs-engine
$string = trim(preg_replace('/\t/', '', $string));
$string = trim(preg_replace('/\t/', '', $string));
This works for me. Remove the gof @Mr. Aliens answer.
这对我有用。删除g@Mr. 外星人回答。

