我有一个以下格式的字符串:
firstlayer{secondlayer;secondlayer,secondlayer};firstlayer{secondlayer;secondlayer}
我现在想要排除“{}”标签之间的所有值,以便我可以简单地用分号分解字符串。 - >我想获得所有第一层值。
编辑: 我的第一次尝试是这样的:
preg_match_all("(.*?)~\{\}~(.*?)", $string,$match);
但它似乎不起作用......
答案 0 :(得分:1)
$str = 'firstlayer{secondlayer;secondlayer,secondlayer};firstlayer{secondlayer;secondlayer}';
if (preg_match_all('~(\w+)\{(.*?)\}~', $str, $m)) {
print_r($m);
}
输出是:
Array
(
[0] => Array
(
[0] => firstlayer{secondlayer;secondlayer,secondlayer}
[1] => firstlayer{secondlayer;secondlayer}
)
[1] => Array
(
[0] => firstlayer
[1] => firstlayer
)
[2] => Array
(
[0] => secondlayer;secondlayer,secondlayer
[1] => secondlayer;secondlayer
)
)
答案 1 :(得分:0)