我想从一个包含括号的字符串创建一个数组,例如 {! !}。但是,不应显示封装字符串开头和结尾的空格。
$string = "{! This should be in the output !} this should not be in the output {!show_in_output!} don't show {! show !}";
preg_match_all("/{!(.*)!}/Us", $string , $output);
结果数组如下所示:
Array
(
[0] => Array
(
[0] => {! This should be in the output !}
[1] => {!show_in_output!}
[2] => {! show !}
)
[1] => Array
(
[0] => This should be in the output
[1] => show_in_output
[2] => show
)
)
但它应该看起来像这样:
Array
(
[0] => Array
(
...
)
[1] => Array
(
[0] => This should be in the output
[1] => show_in_output
[2] => show
)
)
有没有办法通过修改后的正则表达式来实现这一点?谢谢!