lau*_*kok 1 php regex whitespace preg-replace
如何剥离所有空白区域 ?
我把它作为我创建的包装器的输入,
[b] bold [/b]
所以在将文本转换为粗体之前,我想剥去所有空白区域,并将其转换为[b]bold[/b],
$this->content = preg_replace("/\[(.*?)\]\s\s+(.*?)\s\s+\[\/(.*?)\]/",
"[$1]$2[/$3]",
$this->content);
Run Code Online (Sandbox Code Playgroud)
但它不起作用!你能帮帮忙吗?
不需要基于正则表达式的解决方案.你可以简单地str_replace用作:
$input = "[b] bold [/b]";
$input = str_replace(array(' ',' '),'',$input);
echo trim($input); // prints [b]bold[/b]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23847 次 |
| 最近记录: |