- array_map: documentation ( source)
- array_combine: documentation ( source)
- array_slice: documentation ( source)
- preg_match_all: documentation ( source)
- var_export: documentation ( source)
<?php
$data='intervals [1]:
xmin = 0
xmax = 13.139997023062838
text = ""
intervals [2]:
xmin = 13.139997023062838
xmax = 14.763036269953904
text = "Cities are like siblings in a large polygamous family."
intervals [3]:
xmin = 14.763036269953904
xmax = 17.01
text = ""';
$pat='/xmin = (\S+)\s+xmax = (\S+)\s+text = "([^"]*)/';
if(preg_match_all($pat,$data,$m,PREG_SET_ORDER)){
$assoc_multidim=array_map(function($a){return array_combine(['xmin','xmax','text'],array_slice($a,1));},$m);
var_export($assoc_multidim);
}else{
echo "substring extraction failed";
}