php - preg_replace : how do I strip off all white space and  ?

标签 php regex preg-replace whitespace

如何去掉所有的空白和 

我将其作为我创建的包装器的输入,

[b]      粗体      [/b]

所以在将文本变成粗体之前,我想去掉所有的空格和 ,然后把它变成[b]bold[/b]

$this->content = preg_replace("/\[(.*?)\]\s\s+(.*?)\s\s+\[\/(.*?)\]/", 
                "[$1]$2[/$3]", 
                $this->content);

但是没用!你能帮忙吗?

最佳答案

不需要基于正则表达式的解决方案。您可以简单地使用 str_replace作为:

$input = "[b]       bold       [/b]";
$input = str_replace(array(' ',' '),'',$input);
echo trim($input); // prints [b]bold[/b]

关于php - preg_replace : how do I strip off all white space and  ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3789204/

相关文章:

php - 将 **Foo** 替换为 <strong>Foo</stong> (正则表达式)?

javascript - 单击链接时如何在同一页面上显示框

regex - 在 Notepad++ 中使用正则表达式每隔n次出现一个空格添加新行

c# - 如何避免正则表达式中除空格外的所有特殊字符?

php - 用 preg_replace 替换 ereg_replace

php - 正则表达式 preg_replace php

PHP 显示每周两次交货的下一个交货日期

php - laravel find_in_set() sql 和 whereIn 的区别

php - mysite.com 和 www.example.com 之间未维护 session

C# 正则表达式匹配一行中的精确字符串但忽略大小写