<?php
function parse_value_string($string) {
preg_match_all('/([a-z_]+):\s+(.*),/', $string, $matches);
return array_combine($matches[1], array_map(function($val) {
return trim($val, '"');
}, $matches[2]));
}
$test = '{
refresh_token: "xxxx",
access_token: "xxxx",
expires_in: 21600,
}';
$values = parse_value_string($test);
print_r($values);
/*
Array
(
[refresh_token] => xxxx
[access_token] => xxxx
[expires_in] => 21600
)
*/
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
- Array
(
[refresh_token] => xxxx
[access_token] => xxxx
[expires_in] => 21600
)
preferences:
83.77 ms | 408 KiB | 5 Q