preg_replace问题
你好,我正在尝试执行以下操作:
假设我有一个像这样的输入字符串
{stackoverflow is a {cool|great} website|stackoverflow is the {best|greatest}}. {stackoverflow is for {cool|great} coders|stackoverflow is the {best|greatest} site for coders}
如何使用 PHP 将其转换为以下格式
{stackoverflow is a [cool|great] website~stackoverflow is the [best|greatest]}. {stackoverflow is for [cool|great] coders~stackoverflow is the [best|greatest] site for coders}
我正在使用 preg_replace 但找不到有效的解决方案。
总结一下: 嵌套的 { 应该变成 [。
还有|第一层应变成~。
有什么想法吗?
问候
Hello I'm trying to do the following:
Say I have an input string like this
{stackoverflow is a {cool|great} website|stackoverflow is the {best|greatest}}. {stackoverflow is for {cool|great} coders|stackoverflow is the {best|greatest} site for coders}
How can I convert it to the following format by using PHP
{stackoverflow is a [cool|great] website~stackoverflow is the [best|greatest]}. {stackoverflow is for [cool|great] coders~stackoverflow is the [best|greatest] site for coders}
I'm playing with preg_replace but I can't find a working solution.
To sum things up:
The nested { should be turn into [.
And the | on the first level should turn into ~.
Any ideas?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不需要 preg_replace ;)
no need for preg_replace ;)