Given a facebook URL with this format:
....&app_data=eid~423423|pid~23982938|admin~1
I want an array:
[ 'eid' => '423423', 'pid => '23982938', 'admin' => '1' ];
This is how I’m doing it:
$app_data = $signed_request['app_data'];
parse_str(str_replace('~','=',str_replace('|','&',$app_data)), $app_data_params);
Is there a better way to achieve this?
You can use
preg_replaceto eliminate the two calls tostr_replace, but I doubt you’d see any performance benefit to doing so. There’s nothing wrong with the way you’re already doing it.Documentation
preg_replace– http://php.net/manual/en/function.preg-replace.phpparse_str– http://php.net/manual/en/function.parse-str.php