Form form type Data Conversion array array

Source: Internet
Author: User
Tags explode urlencode

Request type for http:

content-type:application/x-www-form-urlencoded

Data formats such as:

mc_gross=399.00&protection_eligibility=eligible&address_status=confirmed&payer_id=xemq4lgll3e8u &address_street=%bf%c6%d4%b0%c2%b72%ba%c5a8%d2%f4%c0%d6%b4%f3%cf%c3&payment_date=22%3a41%3a18+apr+04% 2c+2017+pdt&payment_status=completed&charset=gb2312&address_zip=518000&first_name=li&mc_ fee=15.86&address_country_code=cn&address_name=%c9%ee%db%da%ca%d0%a1%a1%ca%a5%c2%eb%bf%c6%bc%bc& notify_version=3.8&custom=&payer_status=verified&business=yu.yu-facilitator%40zmartec.com& address_country=china&address_city=%c9%ee%db%da%ca%d0&quantity=1&verify_sign= Aepistkyrvdn-dgdcwfo3px0vghvahguyiojwsz3mswiw656jfrcaeii&payer_email=zmartec%40zmartec.com&txn_id= 47265043ly8373011&payment_type=instant&last_name=tao&address_state=guangdong&receiver_email= Yu.yu-facilitator%40zmartec.com&payment_fee=15.86&receiver_id=pead5y5kwxrju&txn_type=web_accept &item_name=sigma%2bsd1000&mc_currency=usd&item_number=&residence_country=us&test_ipn=1&transaction_subject=&payment_gross=399.00& Ipn_track_id=d641e6445fbfc

Convert to:

Array


PHP code

          /**     *  Form type Data Conversion array      *  @param  unknown  $raw _post_array      */    function form_data_to_array ($raw _post_array)      {         $raw _post_array = explode (' & ',  $raw _ Post_array);         $myPost  = array ();         foreach  ($raw _post_array as  $keyval)  {              $keyval  = explode (' = ',  $keyval);             if  (Count ($keyval)  == 2)  {                //   Convert UrlEncode's + to%2B    &NBsp;           if  ($keyval [0] ===  ' Payment_date ')  {                     if  (Substr_count ($keyval [1],  ' + ')  === 1)  {                           $keyval [1] = str_replace (' + ',  '%2b ',  $keyval [1]);                      }                }                  $myPost [$keyval [0]]  = urldecode ($keyval [1]);             }         }    } 

PS:

  Convert UrlEncode's + to%2b                 if  ($keyval [0] ===  ' payment_date ')  {                     if  (Substr_count ($keyval [1] ,  ' + ')  === 1)  {                          $keyval [1] = str_replace (' + ') ,  '%2b ',  $keyval [1]);                     }                 }                  This code according to your own environment, I here is sometimes the wed apr 05 2017 14:37:18 gmt+0800 plus.


This article from "for the Future" blog, declined reprint!

Form form type Data Conversion array array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.