Reputation: 273
I have a problem with my preg_replace. I need to do this for a string who contains more @..@, For example I have :
@CN@ This is a test. Big test @DATE@ and @DATE_END@.
Now I want to get a list with :
My code:
$pattern = '/@[_a-zA-Z0-9]*@/';
preg_match_all($pattern,'',$aData[$i]['tags']);
@CN@,@DATE@,@DATE_END@
Between @...@ can be multiple expressions.
Upvotes: 0
Views: 50
Reputation: 174706
Use preg_match_all
with implode
function.
$str = "@CN@ This is a test. Big test @DATE@ and @DATE_END@.";
preg_match_all('/@[^@]*@/', $str, $match);
echo implode(",", $match[0]);
The above implode function helps to join the array elements with comma as delimiter.
Output:
@CN@,@DATE@,@DATE_END@
Upvotes: 1
Reputation: 91385
I guess you want to use preg_match_all instead:
preg_match_all('/(@[^@]+@)/', $input, $match)
Upvotes: 0