I had the idea the following way, break this text at the point ],[
where I can verify the division of these coordinates and array_map
assemble the coordinates into a new array
associative as follows:
Code:
$texto = '[-23.61025,-46.5871],[-23.61006,-46.58824],[-23.61005,-46.58831],
[-23.60999,-46.5886],[-23.60988,-46.58906],[-23.60969,-46.58946],
[-23.60961,-46.5896],[-23.60944,-46.58979],[-23.60917,-46.59014]';
function get_coordinates($texto) {
$parte = explode('],[', $texto);
return array_map(
function($item) {
list($lat, $long) = explode(',', substr(str_replace(']','',$item));
return ['lat' => $lat, 'long' => $long];
}, $parte
);
}
print_r(get_coordinates($texto));
Exit:
Array
(
[0] => Array
(
[lat] => -23.61025
[long] => -46.5871
)
[1] => Array
(
[lat] => 23.61006
[long] => -46.58824
)
[2] => Array
(
[lat] => 23.61005
[long] => -46.58831
)
[3] => Array
(
[lat] => 23.60999
[long] => -46.5886
)
[4] => Array
(
[lat] => 23.60988
[long] => -46.58906
)
[5] => Array
(
[lat] => 23.60969
[long] => -46.58946
)
[6] => Array
(
[lat] => 23.60961
[long] => -46.5896
)
[7] => Array
(
[lat] => 23.60944
[long] => -46.58979
)
[8] => Array
(
[lat] => 23.60917
[long] => -46.59014
)
)
With this data in array
you can access the positions and view the information as you need
so it’s a text all this?
– novic
Yeah, it’s a string.
– Bruno