var coords = {'x' : 982, 'y' : 1002 };
The above code is returned by the API when accessed via Curl.
I need to analyze the values of x and y in variables. These two values are also not always the same. I'm not sure the best way to do this.
My idea was to use substrto cut the front and back pieces to 'x' : 982, 'y' : 1002use explodeto get var c ' x' : 982and the other with 'y' : 1002, and then use explodeagain to receive 982and 1002, and, finally, remove the spaces.
I am not sure if this is the right way or not. Is this the right way to do this, or will you do it differently?
Also, the API I use is for Javascript, but I use PHP, they don't have a PHP API.
Edit:
I have:
<?php
$result = "var coords = {'x' : 982, 'y' : 1002 };";
$result = substr($result, 13);
$result = substr($result, 0,strlen ($result) - 1);
$json_obj = json_decode($result);
$x_coord = $json_obj->{'x'};
$Y_coord = $json_obj->{'y'};
echo 'x:' . $x_coord;
echo '<br>';
echo 'y:' . $y_coord;
?>
now, but it does not work.
source
share