- array_map: documentation ( source)
- array_combine: documentation ( source)
- print_r: documentation ( source)
- preg_match_all: documentation ( source)
- trim: documentation ( source)
<?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
)
*/