I have these urlencode from Postmant:
rq_uuid=e53473de-0483-44f5-91f0-2be74e58c277&rq_datetime
=2022-03-09 16:33:16&sender_id=TESS&receiver_id=SGRQWES
How can I convert this URLENCODE in an array in PHP so i will have an array like this :
array(
'rq_uuid' => 'e53473de-0483-44f5-91f0-2be74e58c277',
'rq_datetime' => '2022-03-09 16:33:16',
'sender_id' => 'TESS',
'receiver_id' => 'SGRQWES',
etc..
)
CodePudding user response:
parse_str parses string as if it were the query string passed via a URL and sets variables in the current scope (or in the array if result is provided).
https://www.php.net/manual/en/function.parse-str.php
parse_str("rq_uuid=e53473de-0483-44f5-91f0-2be74e58c277&
=2022-03-09 16:33:16&sender_id=TESS&receiver_id=SGRQWES", $arr_params);
print "<pre>";
print_r ($arr_params);
print "</pre>";
CodePudding user response:
Split the string on &
and =
characters, and then urldecode()
each part:
$payload ="rq_uuid=e53473de-0483-44f5-91f0-2be74e58c277&rq_datetime=2022-03-09 16:33:16&sender_id=SGOPLUS&receiver_id=SGWRANCHNEWPOS&password=EPRAIAJO&comm_code=SGWRANCHNEWPOS&member_code=087888088201&member_cust_id=SYSTEM&member_cust_name=SYSTEM&ccy=IDR&amount=15000&debit_from=&debit_from_name=&debit_from_bank=503&credit_to=1111111&credit_to_name=ESPAY&credit_to_bank=503&payment_datetime=2022-03-09 16:33:15&payment_ref=ESP1646818389ZIU2&payment_remark=&order_id=orde01946&product_code=OVO&product_value=087888088201&message=&status=0&token=&total_amount=15000.00&tx_key=ESP1646818389ZIU2&fee_type=S&tx_fee=0.00&tx_status=S&approval_code=3;230819&user_id=orde01946&member_id=087888088201&approval_code_full_bca=087888088201&signature=643928f85730318352d1f42ea926723990029e00b88d0b47ed1ebb67a86d3944";
$values = array();
$nv_strings = explode ('&', $payload);
foreach ($nv_strings as $s) {
$nv = explode ('=', $s, 2);
$name = urldecode ($nv[0]);
$value = (isset ($nv[1]) ? urldecode ($nv[1]) : null);
$values[$name] = $value;
}
print_r ($values);
You can see documentation as well.