如何使用 php preg_match 将 a{a{} b{}} 转换为 a[a[],b[]]?
Group test
{
Group test1
{
#-# Type Val
1 typ1 10
2 typ2 10
3 typ3 10
}
Group test2
{
#-# Type Val
1 typ1 10
2 typ2 10
}
}
如何将上述结构转换为以下结果。
$result=[
"test"=>[
"test1"=>[
0=>["#-#","Type","Val"],
1=>["1","typ1","10"],
2=>["1","typ1","10"],
3=>["1","typ1","10"]
],
"test2"=>[
0=>["#-#","Type","Val"],
1=>["1","typ1","10"],
2=>["1","typ1","10"]
]
]
];
我尝试了很多模式,但都失败了。
我尝试使用正则表达式模式和爆炸功能。我的递归函数失败了。 我想以数组或 json 形式获取输出。我该怎么做。谢谢....
Group test
{
Group test1
{
#-# Type Val
1 typ1 10
2 typ2 10
3 typ3 10
}
Group test2
{
#-# Type Val
1 typ1 10
2 typ2 10
}
}
How can I convert the above structure to the following result.
$result=[
"test"=>[
"test1"=>[
0=>["#-#","Type","Val"],
1=>["1","typ1","10"],
2=>["1","typ1","10"],
3=>["1","typ1","10"]
],
"test2"=>[
0=>["#-#","Type","Val"],
1=>["1","typ1","10"],
2=>["1","typ1","10"]
]
]
];
I tried many patterns, but failed.
I tried with regex pattern and explode function. I Failed in Recursive function.
I want to get the output as array or json. How can i do it.Thanks....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方法分两步:第一步使用递归模式检查整个字符串语法,如果正确,则第二步使用递归函数解析字符串。
演示
An approach in two steps: the first checks the whole string syntax with a recursive pattern, if this one is correct, then the second step parse the string with a recursive function.
demo
我是这样研究的,但是还不够。某些数组数据为空
I did a study in this way, but it was not enough. some array data is empty