fork(3) download
  1. <?php
  2.  
  3. $string = "txn_status=0|txn_msg=success|txn_err_msg=NA|clnt_txn_ref=969239|tpsl_bank_cd=470|tpsl_txn_id=192630337|txn_amt=1.00|clnt_rqst_meta={itc:NIC~TXN0001~122333~rt14154~8 mar 2014~Payment~forpayment}{custname:test}|tpsl_txn_time=26-12-2015 15:56:20|tpsl_rfnd_id=NA|bal_amt=NA|rqst_token=hdfs-df-jkfhskjfhsjkd|hash=jhdsfs54367jhf";
  4. $array = preg_split("/[|=]/", $string);
  5. $output = [];
  6.  
  7. for ($i=0; $i<count($array); $i++) {
  8. $output[$array[$i]] = $array[++$i];
  9. }
  10.  
  11. echo json_encode($output, JSON_PRETTY_PRINT);
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
{
    "txn_status": "0",
    "txn_msg": "success",
    "txn_err_msg": "NA",
    "clnt_txn_ref": "969239",
    "tpsl_bank_cd": "470",
    "tpsl_txn_id": "192630337",
    "txn_amt": "1.00",
    "clnt_rqst_meta": "{itc:NIC~TXN0001~122333~rt14154~8 mar 2014~Payment~forpayment}{custname:test}",
    "tpsl_txn_time": "26-12-2015 15:56:20",
    "tpsl_rfnd_id": "NA",
    "bal_amt": "NA",
    "rqst_token": "hdfs-df-jkfhskjfhsjkd",
    "hash": "jhdsfs54367jhf"
}