PHP:用 preg_replace 替换范围内的特定字符
假设我正在尝试将两个 [lol] 标签内的每个“A”字符替换为“B”。
例如:
“[lol]It'sgreatA确实是A[/lol]”
将变成
“[lol]It'sgreatB确实是B[/lol]”
我试图自己做点什么,但这是徒劳的。 我得到的最接近的是:
preg_replace("%(\[lol\])"."(.*?)([A]+?)(.*?)"."(\[/lol\])%s", "$1$2B$4$5", $haystack);
当然它不会这样工作......
我将不胜感激任何帮助!
谢谢!
Lets say I'm trying to replace every "A" character with a "B", inside two [lol] tags.
For example:
"[lol]It's greatA really isA[/lol]"
will become
"[lol]It's greatB really isB[/lol]"
I was trying to work something myself but it was in vain.
The closest i got is this:
preg_replace("%(\[lol\])"."(.*?)([A]+?)(.*?)"."(\[/lol\])%s", "$1$2B$4$5", $haystack);
of course it doesn't work this way...
I'll appreciate any assistance!
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给出
gives