Reputation: 1
I have one string like the following (the number of the {}
is unknown):
{test}{test1}{test2}{test3}{test4}
Now I like to get the content in {}
out and put them into array. How can I do this? I tried:
preg_match( "/(\{{\S}+\}*/)*")
But the result is wrong. Thanks so much for anyone's help.
Upvotes: 0
Views: 131
Reputation: 14329
<?php
$string = '{test}{test1}{test2}{test3}{test4}';
$parts = explode('}{', substr($string, 1, -1));
This solution avoids using regular expressions which are often slower than simple string functions. Also, many programmers want to avoid regular expressions whenever practical due to preference.
Upvotes: 5
Reputation: 25060
preg_match_all('/{(.*?)}/', $string, $match);
print_r($match[1]);
Upvotes: 5