【问题标题】:Encode/Decode POST data in php在 php 中编码/解码 POST 数据
【发布时间】:2013-09-11 01:55:04
【问题描述】:

我正在使用 cURL 来处理 POST 和检索页面。我注意到我正在尝试发布数据以对其进行编码的网站,例如:

Data=%7B%22Data%22%3A%22%5B%7B%5C%22

如何在 PHP 中对其进行编码/解码?我找到了可以为我做这件事的网站,但我想学习如何自己做。

【问题讨论】:

    标签: php post decode encode


    【解决方案1】:

    看看urldecode()函数:

    echo urldecode('Data=%7B%22Data%22%3A%22%5B%7B%5C%22'); // Data={"Data":"[{\"
    

    还有 urlencode() 函数对其重新编码(包括 = 符号):

    echo urlencode('Data={"Data":"[{\"'); // Data%3D%7B%22Data%22%3A%22%5B%7B%5C%22
    

    您似乎收到了一个 JSON 字符串。您可以通过执行以下操作将其转换为更易于使用的格式:

    $fields = parse_str('Data=%7B%22Data%22%3A%22%5B%7B%5C%22');
    $data = $fields['Data']; //$data now contains the decoded JSON as a string
    $array = json_decode($data); //parse the JSON into an associative array
    var_dump($array); //see what it looks like (could also use print_r($array);)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-21
      • 2019-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      相关资源
      最近更新 更多