Extracting all values between curly braces regex php

Do like this…

<?php
$content ="<p>This is a sample text where {123456} and {7894560} ['These are samples']{145789}</p>";
preg_match_all('/{(.*?)}/', $content, $matches);
print_r(array_map('intval',$matches[1]));

OUTPUT :

Array
(
    [0] => 123456
    [1] => 7894560
    [2] => 145789
)

Leave a Comment