首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >删除bbcode值aftar“]中的空格,然后使用"[”

删除bbcode值aftar“]中的空格,然后使用"[”
EN

Stack Overflow用户
提问于 2022-06-29 11:17:38
回答 1查看 43关注 0票数 -1

是否有办法在trim()或其他人使用之前更正输入??

输入必须首先从

代码语言:javascript
运行
复制
[youtube]       IHu9-Q30Nuw     [/youtube] 
texttexttext


texttext

[code]               codecodecode  codecode codecodecode
codecodecode



codecodecode
[/code] 

代码语言:javascript
运行
复制
[youtube]IHu9-Q30Nuw[/youtube] 
texttexttext


texttext

[code]codecodecode  codecode codecodecode
codecodecode



codecodecode[/code] 
EN

回答 1

Stack Overflow用户

发布于 2022-07-01 17:50:48

(最后做到了:)

输入+代码

代码语言:javascript
运行
复制
// input -------------------
$OLDtext = "[youtube]       IHu9-Q30Nuw     [/youtube] 
texttexttext


texttext

[code]               codecodecode  codecode codecodecode
codecodecode



codecodecode
[/code] 
";

// code -------------------
$NEWtext = preg_replace_callback("/\[(.*?)\](.*?)\[\/(.*?)\]/ism"
                                , 
                                function($match) 
                                {
                                    $TEMPtext   = preg_replace('/\]\s+/', ']', $match[0]); 
                                    return preg_replace('/\s+(\[+)/', '$1', $TEMPtext);
                                }
                                , 
                                $OLDtext
                            );
// print -------------------
echo nl2br($NEWtext);

输出

代码语言:javascript
运行
复制
[youtube]IHu9-Q30Nuw[/youtube] 
texttexttext


texttext

[code]codecodecode  codecode codecodecode
codecodecode



codecodecode[/code]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72800489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档