如何去掉所有的空白和
?
我将其作为我创建的包装器的输入,
[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/