- substr: documentation ( source)
- preg_match_all: documentation ( source)
- json_encode: documentation ( source)
<?php
$str='ID=62981155;IT=OV80419674-62981155_1_3;OD=15.4;|ID=62981157;IT=OV80419674-62981157_1_3;OD=3.1;|ID=62981159;IT=OV80419674-62981159_1_3;OD=8.13;|';
preg_match_all("/(.*?)\=(.*?);/", $str, $match);
//var_dump($match);
$i = 0;
foreach($match[1] as $key => $m){
if($m[0] == "|"){
$i++;
$u[$i][substr($m,1)] = $match[2][$key];
}else{
$u[$i][$m] = $match[2][$key];
}
}
echo json_encode($u);