Maybe someone can help me get coordinates from text to array?
I'm trying use preg_match
but no success.
I can remove geometry":{"paths":[[[**" and **]]}}]})
then use some times 'explode' and get coo, but I don't like this idea
Coordinates:
"geometry":{"paths":
[[[485749.91999999998,6108180.6500000004],
[485722.35999999999,6108206],
[485691.14000000001,6108234.3099999996],
[485400.84999999998,6108513.1500000004],
[485368.60999999999,6108545.46],
[485301.53999999998,6108613.1900000004],
[484054.82000000001,6109868.9100000001],
[484051.17566666665,6109872.6840000004]]]}}]});
To figure out my approach in the comment above. Convert the string to valid JSON. Afterwards you can decode the string using json_decode()
:
$jsonArr = json_decode('{' . substr($string, 0, -4), true);
$coordinates= $jsonArr['geometry']['paths'][0]);
var_dump($coordinates):
So you end up with an array of coordinate pairs:
array(8) {
[0]=>
array(2) {
[0]=>
float(485749.92)
[1]=>
float(6108180.65)
}
[1]=>
array(2) {
[0]=>
float(485722.36)
[1]=>
int(6108206)
}
[2]=>
array(2) {
[0]=>
float(485691.14)
[1]=>
float(6108234.31)
}
[3]=>
array(2) {
[0]=>
float(485400.85)
[1]=>
float(6108513.15)
}
[4]=>
array(2) {
[0]=>
float(485368.61)
[1]=>
float(6108545.46)
}
[5]=>
array(2) {
[0]=>
float(485301.54)
[1]=>
float(6108613.19)
}
[6]=>
array(2) {
[0]=>
float(484054.82)
[1]=>
float(6109868.91)
}
[7]=>
array(2) {
[0]=>
float(484051.175667)
[1]=>
float(6109872.684)
}
}
This is invalid Javascript object notation. Running it through JSONLint shows that it has an invalid array length. You might want to provide more context for your question.
Assuming you have something similar to the above but with valid JSON, you can use the json_decode
method to convert a valid JSON string into PHP arrays and objects.