I'm not able to use the preg_split()
function correctly.
I'm trying to break a String in a array()
via regex but it's not rolling.
$string = "<:termo.9:><:termo.10:><:termo.11:>";
$res = preg_split("/(<:)(nome|termo)(.)(\d+)(:>)/", $string,-1,PREG_SPLIT_DELIM_CAPTURE);
The value assigned to $res
is:
Array (
[0] =>
[1] => <:
[2] => termo
[3] => .
[4] => 9
[5] => :>
[6] =>
[7] => <:
[8] => termo
[9] => .
[10] => 12
[11] => :>
[12] =>
[13] => <:
[14] => termo
[15] => .
[16] => 10
[17] => :>
[18] =>
[19] => <:
[20] => termo
[21] => .
[22] => 11
[23] => :>
)
And I'd really like to:
Array (
[0] => "<:termo.9:>"
[1] => "<:termo.10:>"
[2] => "<:termo.11:>"
)
A palliative solution would be to use the following pattern :
$res = preg_split("/(<:nome\.\d+:>|<:termo\.\d+:>)/", $string,-1,PREG_SPLIT_DELIM_CAPTURE);
And $res
exits:
Array (
[0] =>
[1] => <:termo.9:>
[2] =>
[3] => <:termo.12:>
[4] =>
[5] => <:termo.10:>
[6] =>
[7] => <:termo.11:>
[8] =>
[9] => <:termo.9:>
[10] =>
)
But if you look closely, the conditions imposed are:
(<:nome\.\d+:>|<:termo\.\d+:>)
And the variations of nomenclatures that I can use can increase, like: